rdbende / chlorophyll

A Tkinter widget that fills your code with color
https://pypi.org/project/chlorophyll/
MIT License
42 stars 8 forks source link

Performance improvement suggestion #11

Open rdbende opened 1 year ago

rdbende commented 1 year ago

@Moosems:

@rdbende I think you might want to consider this. Currently chlorophyll highlights the entire text box. For small amounts of code of moderately sized snippets this works fine but with large amounts of code it grinds to a halt. My suggestion is to only highlight what's in the current view and remove the other tags to save speed. The locations of the other tags can be kept in a list but by not highlighting them all at the same time it saves a ton of time. As the Tcl Core itself has noted tags are very slow so minimizing the amount of active tags is very important.

Sample code to test with:

from tkinter import Tk
from chlorophyll import CodeView
root = Tk()
text = CodeView(root)
text.pack()
text.insert("end", "text = BaseText(root, lexer=lexers.PythonLexer, undo=True, font=(\"Courier New bold\", 15), indentation_type=\"space\", indentation_amount=4, bind_string=\"Command\", comment_type=(\"# \", \"\\\"\\\"\\\"\"))\n"*100)
root.mainloop()

@rdbende:

I'm afraid it wouldn't make it much faster, but would make it much more laggy, because it has to constantly highlight everything.

@Moosems:

Why do you say it wouldn't get much faster? And for highlighting everything that's the issue I am trying to avoid by not using as many tags

@rdbende:

Because it has to constantly re-add the tags, as you scroll. The same thing happens in Porcupine, so I know, it's laggy, and doesn't really reduce CPU usage.

@Moosems:

Not if it doesn't move outside the view

Moosems commented 1 year ago

Merge with #9 for a performance update