<blockquote>
<p>[…] it seems the problem indeed only occurs on gtk3 version.</p>
</blockquote>

<p>I can confirm, although I find it weird it does.  I guess the GTK2 version of Scintilla forces more re-highlighting for some reason?</p>

<p>Anyway, I see 4 options:</p>

<ul>
<li>either not bother optimizing (e.g. re-colorize everything), effectively reverting <a href="https://github.com/geany/geany/pull/575" class="issue-link js-issue-link" data-url="https://github.com/geany/geany/issues/575" data-id="94939159" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#575</a>.  I guess this isn't wanted :)</li>
<li>don't bother optimizing too much, and force re-colorizing up to the end of the visible area (<code>sci_colourise(sci, 0, end_of_the_visible_area)</code>).  This is less expensive near the start of a document, but the same near the end.</li>
<li>detect when typenames changed, and only re-highlight (all) in this case.  This would be <a href="https://github.com/geany/geany/pull/518" class="issue-link js-issue-link" data-url="https://github.com/geany/geany/issues/518" data-id="88835961" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#518</a> I guess?</li>
<li>update the visible area <em>until we updated to the start</em>.  This is a fixed version of the current optimization, by continuously updating the visible area until we updated the start of the document.</li>
</ul>

<p>I tried implementing the last option in <a href="https://github.com/geany/geany/commit/71b80edf04a5b5d565da45abe0a71a32debaf316" class="commit-link"><tt>71b80ed</tt></a> (in my <a href="https://github.com/b4n/geany/commits/typename-highlight-fix">typename-highlight-fix branch</a>).  It's not that hard to do actually, as Scintilla generously does it for us going forward (the part after the visible area) -- which is why we don't suffer too much from the bug at hand currently --, so we only need to track what was the lowest position we updated since the request.  This should be fairly cheap as it's incremental, and might even get "coalesced" with other scheduled updates.</p>

<p>What do you think?  Also, <a href="https://github.com/techee" class="user-mention">@techee</a> is this (or another) option OK regarding performances?  I didn't perform the stress-tests you did leading to the current optimization, yet it might be interesting to.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly or <a href="https://github.com/geany/geany/pull/1022#issuecomment-218930776">view it on GitHub</a><img alt="" height="1" src="https://github.com/notifications/beacon/ABDrJz4qsfH4qyay1a_Zeqe8LMBAw-9pks5qA9VDgaJpZM4IXArK.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/geany/geany/pull/1022#issuecomment-218930776"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>