How best to deal with gigantic source code files i

2020-07-19 04:52发布

问题:

I'm working on a project which makes substantial use of code generation. Some of the files it generates contain >0.25 million lines of code. VS (2K5) doesn't cope too badly, but R# (4.01) throws an out of memory exception every two minutes or so.

Splitting them out into partial classes/separate files isn't an option in the immediate term, though it may be later.

Are there any clever IDE tricks to dealing with this?

EDIT: so people are immediately saying (very sensibly) 'don't have a file that big' and suggesting ways to break it out into smaller files.

That's fine, but I'm on a time-boxed task taking a look around and deciding what to optimise. My problem is very specifically 'how to view an insanely big file in an IDE without pain', not 'how to refactor the project'. For purposes of the question please imagine the file is read-only. :)

回答1:

Seems like this R# tool (is that Resharper?) is the problem. Can you disable it? Otherwise, changing the file type for the generated code might make sense - presumably, you aren't going to be doing major editing on those files, so losing syntax coloring and other features specific to source files wouldn't be an issue.



回答2:

I would at least change huge files extention to something like .cpp_gen or .cpp_huge to remove syntax highlighting, outlining etc. and then reassign build tool back to C/C++ compiler tool for them.



回答3:

WOW!

250 000 lines of code?

you should think not in a machine point of view, but in a human been point of view. Let's say that you want to pass that code to someone else, can you see the time to see what the code does?

Design Patterns were made to deal with this ind stuff, try to start small, refactoring it, then go deeper and start applying more D.P.

you will have less and less lines of code, and Yes, one of the best tricks is to separate into several files according to it's propose.



回答4:

Assuming you're not hand-editing your generated code. (=BAD IDEA!!)

You could put the generated files in a separate solution that you compile from the command line and then reference those dll's from the project you're working in.



回答5:

Is the problem when you open the file for editing in Visual Studio? I've noticed that VS editor can be quite slow and inefficient on large files. Also, you could try turning off certain options, e.g. word-wrapping kills my machine for some reason.

Otherwise you could use something else like Textpad with syntax highlighting installed to edit the problematic large source file... not as nice, for sure.



回答6:

Don't use visual studio. There is too much going on in VS.

Since the file is read only, you wont be using any IDE features (Intellisense, Refactoring tools, formatting).

You will probably get better performance using a simpler application, such as notepad++ for simply viewing the file. Notepad++ will do standard language highlighting if you like color.



回答7:

Can't you break up the files and use the preprocessor to bring them back together when you compile?



回答8:

It must be possible somehow to group large chunks of those files in separate libraries. You'd then separate them into several projects. Tried this? What the is the current structure of your source code/ project?