large files, very slow editor, no fix?

18 visualizaciones (últimos 30 días)
Scott
Scott el 12 de Ag. de 2011
Changes to the editor in R2011 have dramatically slowed down the editor when working with large m-files (e.g. 1000's of lines). I have been in correspondence with support staff, who tell me to disable cell mode and break up the file into smaller files.
Disabling cell mode does help somewhat, but there is still a lot of latency while typing. It can be several seconds to see what was typed. Even scrolling is choppy.
So the next step is break up the large file. But here's the problem. Most of the functions within the file are nested functions, which share the scope of the parent functions. How do I move the nested functions to separate files and maintain the behavior of nested functions?

Respuesta aceptada

Michael Katz
Michael Katz el 12 de Ag. de 2011
Try also increasing the size of the Java heap. File -> Preferences -> General -> Java Heap Memory. It may not help, depending on where the time is being spent, but it's worth a shot.
  2 comentarios
Scott
Scott el 12 de Ag. de 2011
That fixed it completely! I octupled the Java heap and the editor is snappy and vivacious again.
Thank you user community!
Scott
Scott el 14 de Ag. de 2011
Well, maybe that isn't the only problem. At first, the editor is fast, but before long it slows way down again.

Iniciar sesión para comentar.

Más respuestas (5)

Andrew Drake
Andrew Drake el 27 de Ag. de 2013
put "exit" on the first line
  1 comentario
Scott
Scott el 27 de Ag. de 2013
At first, I thought this was just a snarky response. But then I got to thinking it might have some impact on the MTree functionality, so I tried it.
Indeed, it effectively turned off MTree and let me edit the file without any slowdowns. Of course, it also turns off error checking and disables the "show functions" popup menu, but keeps code folding functional.
It is a lot more convenient than the "official" Matlab workaround of issuing "com.mathworks.services.Prefs.setBooleanPref('CodeParserServiceOn',false)" and restarting Matlab. At least I don't have to wait through a restart. I just have to remember to remove the "exit" before saving changes.
An alternative to "exit" on the first line would be anything that produces an error, such as a simple "x".

Iniciar sesión para comentar.


Oleg Komarov
Oleg Komarov el 12 de Ag. de 2011
By moving the nested functions to separate files you will:
  1. Lose the ability to see the parent's function workspace
  2. Other functions will see them and you may get into conflicts
To solve 2. you can make the ex-nested functions private.
To solve 1. you have two options:
  • Add inputs to your ex-nested functions (no big news here).
  • [STRONGLY UNRECOMMENDED] Hardcode assignin calls.
  4 comentarios
Scott
Scott el 12 de Ag. de 2011
I suspect the problem would persist with subfunctions, too. My guess is that the slowdown comes from the new features in the editor, such as expanded use of syntax coloring, and the highlighting of all instances of the word adjacent to the cursor throughout the entire file. I don't see a way to turn that off.
I wish there were a command that would expand the scope of a function to include the scope of another function, like ExpandScope('parent_function').
Michael Katz
Michael Katz el 12 de Ag. de 2011
If the latency is related to the code structure, using subfunctions would help, as the editor needs more power to process deeper into nested code. Without seeing the code, it's hard to make a good judgement, but if the nesting is several levels deep, maybe it can be rewritten to use fewer levels. Also consider using a class object if that data has to be shared within that many function calls.

Iniciar sesión para comentar.


Daniel Shub
Daniel Shub el 12 de Ag. de 2011
You could switch to an editor like emacs/vim.
You could move your nested functions to separate files. Then write another function that writes a new mfile that integrates your nested functions into the main function.
Divide your code up into smaller and reusable blocks. Use structures to efficiently pass the formerly nested functions arguments.
  2 comentarios
Scott
Scott el 12 de Ag. de 2011
OK, I'm open to the idea of a new editor. Would it integrate well into Matlab? I'm using Win7 64bit.
Would it use color to differentiate the various parts of the syntax? Would it flag syntax errors and make suggestions for correction? Does it fold sections of code? Autosave? Does it permit stepping through the code in debug mode, with the value of variables popping up when hovering over them? Will it let me jump to the offending line of code after clicking on an error message?
If so, I'm very interested in looking into this!
Daniel Shub
Daniel Shub el 12 de Ag. de 2011
I don't use emacs with MATLAB, but more details can be found at:
http://blogs.mathworks.com/desktop/2009/09/14/matlab-emacs-integration-is-back/
and
http://matlab-emacs.sourceforge.net/faq.shtml
for more details ...
Would it use color to differentiate the various parts of the syntax? Yes
Would it flag syntax errors and make suggestions for correction? To some degree. It integrates with mlint.
Does it fold sections of code? I believe there are emacs plugings for this.
Autosave? Yes
Does it permit stepping through the code in debug mode, with the value of variables popping up when hovering over them? I am not sure on this one, but it looks like it.
Will it let me jump to the offending line of code after clicking on an error message? Yes

Iniciar sesión para comentar.


Andreas Goser
Andreas Goser el 12 de Ag. de 2011
I know of a couple of examples where disabling cell mode completley healed the issue. Actually, I know only of one counter-example and this was a user who had his large MATLAB Code on an external server (mapped drive). If this is the case for you, please try putting the file local.
  3 comentarios
Andreas Goser
Andreas Goser el 12 de Ag. de 2011
Well, it was worth a try...
Scott
Scott el 12 de Ag. de 2011
I appreciate your giving my problem attention!

Iniciar sesión para comentar.


per isakson
per isakson el 12 de Ag. de 2011
An object oriented design with methods in a separate @-folder should solve the problem with the editor.
Rewriting object oriented code, which is implemented with nested functions, might not be as bad as it sounds. I've done it a few times (for other reasons) with pre-R2008a m-files. At most a couple of thousand lines. However, it is certainly not a quick-fix.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by