Jiri,
I have pasted the questions and Neils answers below with my comments and I'm sure others may have more info.
Jiří Techet:
I have a question regarding the use of SCI_COLOURISE. It is used in Geany at several places and it's call is rather expensive so I'd like to avoid it as much as possible.
Most of the time all of the buffer you see should be styled automatically by Scintilla in a lazy way. That means that Scintilla does not normally style much beyond the portion currently visible. There are times when you want the whole file to be styled, such as when exporting the file as HTML/PDF/RTF. There may also be workarounds to problems in Scintilla and its possible some of these workarounds are no longer needed.
- After SCI_SETKEYWORDS - this basically happens after every keystroke because we colorize typenames using keywords (we've already talked about that if you remember).
Possibly Geany wants the document styled up to some point immediately so it can use the style information.
As best I can tell this one is extraneous, it would just change names from/to type colourising which AFAICT doesn't affect anything else, they are both code type styles etc. So long as the visible area is colorised by Scintilla so when a newly typed name matches a keyword it will highlight, then it doesn't look like doing it manually is useful.
- Immediately after SCI_SETTEXT when loading (or reloading) file.
This may or may not be needed depending on Geany’s features. One reason for doing this is if you want to perform a global fold operation since folding depends on fold information and thus on styling.
This one is more likely useful, since lots of features need to know the styles of things outside the visible area, for example to avoid considering characters in comments and strings when counting braces for scopes.
I tried to remove SCI_COLOURISE in all these cases and interestingly everything seems to work. In particular, I'm most interested in optimizing the case (1) above and after looking at the code, it seems that LexState::SetWordList() sets the Document::ModifiedAt() to 0 if something changes and in Editor::Paint() the document gets colored if needed. Am I right this case is already handled by Scintilla and doesn't require the explicit SCI_COLOURISE call?
It of course depends on what features you use, you would have to check nearly everything.
Its going to depend on when and how Geany uses style information.
Is the SCI_COLOURISE call needed in the other cases above (or maybe in other words, is there any Scintilla API call that requires SCI_COLOURISE to be called explicitly)?
The application may need more text to be styled than Scintilla will perform automatically. For example, when performing brace matching and the corresponding brace is below the visible area then you may want to call SCI_COLOURISE over each line before checking it for braces.
This sort of thing is used in several places in Geany, styles are used to avoid considering braces parens etc in strings and comments (see highlighting_is_code_style()).
Is it possible that Scintilla behaved differently in the past in this respect? This would explain the SCI_COLOURISE calls in Geany.
This is why we have source control: go looking for changes in Geany involving SCI_COLOURISE and see why they occurred.
I'm sure Colomban has a better understanding as well.
Cheers Lex
On Fri, Jun 26, 2015 at 11:40 AM, Lex Trotman elextr@gmail.com wrote:
Jiri,
I have pasted the questions and Neils answers below with my comments and I'm sure others may have more info.
Jiří Techet:
I have a question regarding the use of SCI_COLOURISE. It is used in
Geany at several places and it's call is rather expensive so I'd like to avoid it as much as possible.
Most of the time all of the buffer you see should be styled
automatically by Scintilla in a lazy way. That means that Scintilla does not normally style much beyond the portion currently visible. There are times when you want the whole file to be styled, such as when exporting the file as HTML/PDF/RTF. There may also be workarounds to problems in Scintilla and its possible some of these workarounds are no longer needed.
- After SCI_SETKEYWORDS - this basically happens after every
keystroke because we colorize typenames using keywords (we've already talked about that if you remember).
Possibly Geany wants the document styled up to some point immediately
so it can use the style information.
As best I can tell this one is extraneous, it would just change names from/to type colourising which AFAICT doesn't affect anything else, they are both code type styles etc. So long as the visible area is colorised by Scintilla so when a newly typed name matches a keyword it will highlight, then it doesn't look like doing it manually is useful.
This is the main use of SCI_SETTEXT I was interested in and yes, I also think this one can be (safely) removed. It isn't called already by languages not highlighting typenames like e.g. python so there's very little risk that anything breaks by removing it because it would have already been broken for all the scripting languages.
- Immediately after SCI_SETTEXT when loading (or reloading) file.
This may or may not be needed depending on Geany’s features. One
reason for doing this is if you want to perform a global fold operation since folding depends on fold information and thus on styling.
This one is more likely useful, since lots of features need to know the styles of things outside the visible area, for example to avoid considering characters in comments and strings when counting braces for scopes.
Yes, this one should probably stay. But I would delay it's call until the document is actually shown to improve Geany start time with many tabs open.
For completeness, there was also another case in my original email:
3. When reloading configuration files which can change various aspects of Scintilla (keywords, style coloring, etc.)
but since this one is called only when changing config files, it's not worth worrying about.
(plus one more use in brace_match() but it's a single-character one and doesn't matter either)
Cheers,
Jiri
On Fri, Jun 26, 2015 at 1:21 PM, Jiří Techet techet@gmail.com wrote:
- Immediately after SCI_SETTEXT when loading (or reloading) file.
This may or may not be needed depending on Geany’s features. One
reason for doing this is if you want to perform a global fold operation since folding depends on fold information and thus on styling.
This one is more likely useful, since lots of features need to know the styles of things outside the visible area, for example to avoid considering characters in comments and strings when counting braces for scopes.
Yes, this one should probably stay.
OK, just checked and things like "fold all" don't work without it so it definitely needs to stay.
But I would delay it's call until the document is actually shown to improve Geany start time with many tabs open.
Should have checked before I wrote anything - this is already the case now so no change needed in this respect.
Cheers,
Jiri