codemaid
codemaid copied to clipboard
Codemaid makes Visual Studio crash/restart when reorganizing a document of around 17.000 lines.
Environment
- Visual Studio version: 2017 Pro
- CodeMaid version: 11.0
- Code language: VB.NET
Description
CodeMaid makes Visual Studio crash/restart when reorganizing a document of around 17.000 lines. If I split the document (the P/Invokes) in smaller amounts, like various classes/documents of 5.000 lines each one, then it works fine when reorganizing each document. So this appears to be a memory issue.
An additional problem is that if the file has unsaved changes before reorganizing the document, all the changes will be lost / not recovered by auto-recovery feature...
Steps to recreate
-
Copy and paste this entire class elsewhere: https://paste.ubuntu.com/p/CWQQHr6fbY/ Note: it expires on 06/July/2019
-
Try to reorganize the document by selecting "Reorganize Active Document" option. At this point, after few seconds CodeMaid will print a message in the VS status bar saying the document is successfully reorganized, however, the VS UI will not respond to keyboard and mouse input, and after some seconds (like 30 or so) VS will restart itself, and the document will not be reorganized.
Thank you for reporting the issue. I am able to reproduce it, and this is a known issue that the larger the file the larger the resources required to process it. As you've seen breaking up the file is the known workaround. There is some more information on #83 if it helps.
Thanks for comment... after 13 days of the issue report publication (alert superstitious people), but could you please extend your answer to clarify whether or not this issue could be inspected and finally fixed directly in CodeMaid?. Unfortunately, splitting the original file into smaller total amount of lines is not a viable option in my scenario; at least not for the class that I shared as example.
In the thread that you linked, you stated that "enabling multi-threading performance (which is off by default) actually makes things worse for some users", however I can't find any multi-threading related option in CodeMaid settings to try disabling/enabling it and see the results.
After read that thread, I don't know whether CodeMaid still rely on VsRegexFinder class or on Roslyn. But the thread is from year 2015 and there you stated "In the future (VS2015+) the COM APIs go away and CodeMaid can utilize Roslyn which may bypass the issue." and that gives me some hope about you being able to fix this issue...
In short, could you do/think something to fix the issue in CodeMaid?. Sure there are much people that faces this issue when trying to reorganize very large classes (like mine)...
Anyway, I couldn't totally understand why the alleged memory leak of CodeMaid/VsRegexFinder could eat all the memory to reorganize a document. I mean, if its a memory leak, then really it should allocate and don't free an insane amount of memory per call to sort members, because my PC has 16 GB of RAM, and I tried to reorganize that document with only Visual Studio open in foreground... then for me it's a little bit insane to think about it.
Thanks for your time and support.
We are still heavily relying on COM APIs for CodeMaid so those memory issues linked in the other issue are still applicable. We still plan to move over to Roslyn but it's a significant effort and a long running effort. Roslyn isn't a magic bullet either to be candid, the larger the file the larger the resource demands.
We took away multi-threading performance in a later version, so that thread comment is no longer applicable.
I don't mean to be flippant. 17000 lines, in a single file? Is there a reason you need that big of a file? Can you not at least split it into 2 files, if not a 100?
My project provides a vast amount of P/Invokes from Win32 libraries. For example I have a file with name User32.vb, which provides functions from User32.dll. Every function in my source-code is xml documented, and this increases the total amount of lines in the file, a lot. A similar thing would be Vanara's source-code.
Is not necessary to have it all in a file of 17.000 lines, of course I could split them into multiple files like for example you can see in Vanara's source code (which anyway have files of more than 9.000 lines with P/Invoke definitions), but having all the P/invokes from one dll file in a single class file, would be the way to keep it ordered by name... if I could use a tool like CodeMaid to sort function members by name in that file; and after that maybe I could start splitting them into two files from A-M and N-Z or by thematic, but to do that first I need to be able sort the members name, and I can't do that due CodeMaid can't handle that amount of lines, and I can't do that task manually without automation...
PS: please note that online C# source-code reference from Microsoft Team has class files of much more than 20.000 lines. Sometimes it is the way to keep things ordered, not a bad habit.
Ok thanks for the explanation.
In the mean time you could split the file before sorting, into the size CM could handle, and then sort. Then move the top of each to appropriate file and resort. Manual I know.
Or I guess digin and try a PR, not easy either.
Thanks again, I was just curious what kind of code would have 17k lines per file.
Get Outlook for Androidhttps://aka.ms/ghei36
From: Elektro [email protected] Sent: Saturday, August 17, 2019 10:19:16 PM To: codecadwallader/codemaid [email protected] Cc: Steven Cramer [email protected]; Comment [email protected] Subject: Re: [codecadwallader/codemaid] Codemaid makes Visual Studio crash/restart when reorganizing a document of around 17.000 lines. (#655)
My project provides a vast amount of P/Invokes from Win32 libraries. For example I have a file with name User32.vb, which provides functions from User32.dll. Every function in my source-code is xml documented, and this increases the total amount of lines in the file, a lot. A similar thing would be Vanara's source-codehttps://github.com/dahall/Vanara/tree/master/PInvoke.
Is not necessary to have it all in a file of 17.000 lines, of course I could split them into multiple files like for example you can see in Vanara's source code (which anyway have files of more than 9.000 lines with P/Invoke definitions), but having all the P/invokes from one dll file in a single class file, would be the way to keep it ordered by name... if I could use a tool like CodeMaid to sort function members by name in that file; and after that maybe I could start splitting them into two files from A-M and N-Z or by thematic, but to do that first I need to be able sort the members name, and I can't do that due CodeMaid can't handle that amount of lines, and I can't do that task manually without automation...
PS: please note that online C# source-code reference from Microsoft Team has class files of much more than 20.000 lines. Sometimes it is the way to do things, not a bad habit.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/codecadwallader/codemaid/issues/655?email_source=notifications&email_token=AACXGY5H2X7QXP435KBGPUTQFAJHJA5CNFSM4HUAXZD2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4QNSFY#issuecomment-522246423, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACXGYYFZYVOFB26AG4TTMTQFAJHJANCNFSM4HUAXZDQ.
I was just curious what kind of code would have 17k lines per file
How do you manage code changes in periodically auto-generated files?
In my scenario, the code for the (connected service) WCF Web Service is auto-generated from WSDLs. Visual Studio employs svcutil to generate C# code in a single file without any specific order (apart from the WSDL's structure). This lack of order makes it challenging to track changes when updating the file with a new (or even the same) WSDL, due to the disorder among the file's classes.
To tackle this issue, I've employed CodeMaid in Visual Studio 2022 to alphabetically reorganize the classes in the generated file based on class names.
The current reorganization process has been running for over 24 hours on my i9-12900 with 64GB DDR5 RAM and a PCIE SSD.
While the file appears to be organized (with visible changes in order), attempting to save it results in Visual Studio crashing. It seems that CodeMaid has made some progress, but I'm uncertain about the completion status.
I'm curious if there's an alternative approach aside from splitting the file into multiple parts. Unfortunately, my files exceeds 100k lines, making splitting impractical for me. Any suggestions or insights?