-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve style resolution performance #453
Conversation
This uses a simple cache to keep track of already-computed scope stacks, which greatly improves the efficiency of computing of new styles (at some cost in memory.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't experimented carefully with this, but looks good, and looking forward to the performance improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable to me. One caveat: I don't remember why we went with this approach instead of using the pushes/pops I use in syntect. I know we discussed it a bunch, but I can't comment knowing that.
Also I seem to recall that at some point in that discussion I did benchmarks on how many different stacks you could expect to see in typical and atypical files. If you find the right old issue discussion you may find a comment with those results. That may inform concerns about memory.
// a prefix tree. | ||
/// style state of existing scope spans, so we can more efficiently | ||
/// compute styles of child spans. | ||
style_cache: HashMap<Vec<Scope>, StyleModifier>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If hashing shows up any significant amount in the time profile, you can switch this to use a FNV hasher, which is what I use in syntect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trishume okay, good note, thanks!
This patch significantly improves the speed at which we resolve scope spans into styles and greatly improves startup performance, especially noticeable on debug builds.
before:
after: