stefanceriu / SCXcodeMiniMap

Sublime Text like Minimap for Xcode
GNU General Public License v3.0
1.03k stars 87 forks source link

Workaround for slowing down coding on large files #32

Closed designatednerd closed 9 years ago

designatednerd commented 9 years ago

This is a workaround for issues like #29.

designatednerd commented 9 years ago

So, a few more details on this:

By attaching the Time Profiler to Xcode, I saw that the overwhelming majority of the overhead is coming in the drawing and layout code of the MiniMap's text view. The .25 second delay between calls that was included by default was perfectly sufficient for relatively small files, but as files get longer, the delay needs to grow with them or performance tanks as the text view re-renders.

What I've done here is add a mechanism to cache how long a file is when it's rendered, then calculate how long the next delay in rendering should be based on that length. Based on my highly scientific "see what feels about right" method, I determined that we should add a single multiple of the default length for every 150 lines of code.

I certainly wouldn't deem this a "fix" - it's more of a tradeoff: A slight delay in rendering changes in exchange for more responsive typing. A file of 1500 lines would see a delay of 2.5 seconds, anything under 150 lines would still be .25 seconds, but I can actually type in the damn file.

I think the only real way to make this responsive is to render the contents of the TextView as an image on a background thread and then display them as an image in a scrollview instead of as an actual TextView. I think this is a totally viable interim solution until someone has time to do that.

Very, very open to suggestions on this PR though. Love this plugin, and would love to make it usable for all.

stefanceriu commented 9 years ago

Thank you for the pull request, I took the liberty of making a few changes, hope you don't mind.

I'm pretty sure rendering the textView as an image wouldn't be any faster as you would still need to go to the Xcode editor's layoutManager to fetch the temporary attributes.

As far as I can tell the only way to make any significant performance improvements is to switch to a different parser for syntax highlighting and dispatch that to a background thread which might prove to be tricky without knowing exactly what changes happened (which I wasn't able to hook into).

What you can for large files for now is to disable syntax highlighting all together.

Cheers, Stefan

designatednerd commented 9 years ago

Awesome! Thanks!