Home

High memory usage by LINQPad, intellisense to blame?

edited October 2023

I'm trying to prototype a webapi built on asp.net core and entity framework core and will eventually add graphql.

For some background, the database context consists of 250+ entities and I think it's causing issues for anything that has code completion. I haven't tried developing the context through Visual Studio yet, just Visual Studio Code. And with that project, typing is agonizing since the .net host is running at 100% CPU for every keypress. I switched back to using omnisharp and it's running a little better at least.

With the context completed, I added a reference to the assembly and am building out the script. Before I added the reference, I was able to develop it normally. However once I added the reference and implemented some endpoints and queries, I'm finding it getting sluggish the longer I have the query open. I saw memory usage reach over 6GB at one point and killed a lot or processes (I only have 16GB on my dev machine).

Forcing garbage collection shaves a couple hundred MB. Only closing the query completely frees all the memory and it's back to normal levels. And this happens without even running the query and just modifying the script. It starts out fine when I initially open the script and do nothing. Only until I start making changes to the file, memory usage grows at an alarming rate. The script itself is only 300 or so lines long and is just a standard asp.net core app. Can this be reviewed?

LINQPad Beta 7.8.6
.NET SDK 7.0.401

Comments

  • edited October 2023

    I left it idle yesterday and it climbed up to ~7GB and 100% memory usage. Something is running away with the memory. And closing the script, memory usage dropped back to ~700MB.

    Trying a new approach and rather than referencing the assembly directly, I created a database connection (in the list on the left) and used the context I created. Ran a couple of small queries and memory usage is not increasing nearly as fast.

    Tried to copy the script to a new one to try to use the connection. But memory usage jumped to ~2.4GB just attempting to run it. It doesn't seem to be growing though. As I continue to use it, memory usage goes up a bit (slower) and has performance hitches as I type. But then I left it idle, then memory usage dropped back down to 2.4GB. Running the script, overall usage jumps to 3.5GB (500MB from the app) but seems fairly stable. Something about it using the context as a database connection seems to be inherently efficient than adding the reference directly.

  • When you say typing was agonizing since the .net host is running at 100% CPU for every keypress, was that with LINQPad or with Visual Studio Code? What was the memory usage like there?

    Also, are you able to create a minimum repro? I've tried creating a database with 10,000 tables, each with 30 columns, and then created both LINQ-to-SQL and EF Core connections. However, I cannot get the GUI to consume much above 600MB after playing in the editor.

  • When you say typing was agonizing since the .net host is running at 100% CPU for every keypress, was that with LINQPad or with Visual Studio Code? What was the memory usage like there?

    VSCode. It was strange because memory usage seemed fine, it was the CPU usage was constantly churning. My guess is the language server is either parsing out the current code file to update the symbols and mark errors and whatnot. This was on my work dev laptop and it's not the most powerful thing in the world.

    I'll see if I can repro with an AdventureWorks database or something. And provide the source to that context. I don't believe I'll be able to share the context that I was working on, that's for work. Perhaps I could share with you the dependencies used in generating the context as well as the designer code. I was using handlebars and it had a lot of support files. Perhaps that was a factor in the issue?

  • Worst case scenario, I'll try recording video with it occurring with task manager open. Is there any logging I can enable in LINQPad that I could use to help diagnose the issue?

  • @JoeAlbahari I messaged you a video recording going and some additional details about the issue. If I can create a sharable repro, I'll share here.

  • Thanks, but it doesn't really help me. What I need is an MRE. However, if you experience similar problems in VS and VS Code, it may be a Roslyn-related issue, which I would have limited ability to address.

  • @JoeAlbahari I couldn't replicate the issue so I sent you the script and context to try to replicate the issue.

Sign In or Register to comment.