Community
Participate
Working Groups
Formatting a big file using a formatter implemented as a subclass of AbstractDeclarativeFormatter can take a very long time: Around 10 seconds for a 4000 lines file (this of course also depends on the grammar and actual formatting rules). I traced the problem back to the FormattingConfigBasedStream$Line#getIndentation() method, where FormattingConfig#getIndentationSpace() is potentially called many times. By default each call will end up in PreferenceStoreIndentationInformation#getIndentString() where two calls to the Eclipse IPreferenceStore are made. These can be expensive. Changing the PreferenceStoreIndentationInformation to cache the value from the IPreferenceStore and register itself as a listener to the IPreferenceStore (to invalidate the cache) reduces the time spent formatting considerably. I will attach a corresponding patch.
Created attachment 181273 [details] patch for PreferenceStoreIndentationInformation
Created attachment 181274 [details] updated patch Surprising how easy it is to introduce a new bug...
Hi Knuth, thanks for the observation and thanks for the patch. However, rather than adding a property listener to the property store, I'd like the idea to have org.eclipse.xtext.formatting.impl.FormattingConfigBasedStream.Line.getIndentation(int) cache the indentation-value. An instance of FormattingConfigBasedStream lasts exactly for one formatting operation (i.e. resource.save() or CTRL+SHIFT+F) and thereby provides the right context for caching.
sry, never mind the "h" ;)
Created attachment 181367 [details] updated patch 2 Hi Moritz, Makes sense. I've attached a revised patch.
Hi Knut, I prefered you former solution as it worked transparently for any possible client of IIndentationInformation. I'm currently discussing this with Moritz. Regards, Sebastian
Then how about both? ;-)
(In reply to comment #7) > Then how about both? ;-) We came to the conclusion that the PreferenceChangeListener-approach has the advantage that it works transparently for more clients. Please feel free to cache the indentation in the formatter, too, if it improves anything.
PreferenceChangeListener patch applied and pushed to master.