feat: introduce a LRU compiled style cache for the HTML formatter#938
Merged
alecthomas merged 1 commit intomasterfrom Feb 27, 2024
Merged
feat: introduce a LRU compiled style cache for the HTML formatter#938alecthomas merged 1 commit intomasterfrom
alecthomas merged 1 commit intomasterfrom
Conversation
``` 🐚 ~/dev/chroma $ benchcmp before.txt after.txt master benchmark old ns/op new ns/op delta BenchmarkHTMLFormatter-8 160560 77797 -51.55% benchmark old allocs new allocs delta BenchmarkHTMLFormatter-8 1267 459 -63.77% benchmark old bytes new bytes delta BenchmarkHTMLFormatter-8 52568 25067 -52.32% ```
gkaikoponen
reviewed
Feb 27, 2024
|
|
||
| func (l *styleCache) get(style *chroma.Style) map[chroma.TokenType]string { | ||
| l.mu.Lock() | ||
| defer l.mu.Unlock() |
There was a problem hiding this comment.
Can this be turned into a sync.RWLock? Most cases will probably only write to this cache once so it'd be a shame to introduce potential lock-contention if there are many reads.
Something like https://stackoverflow.com/a/70236841 should dodge the gotchas with finishing the read-unlock-defer before grabbing the write lock
Owner
Author
There was a problem hiding this comment.
Possibly, send a PR through if you're interested.
Owner
Author
There was a problem hiding this comment.
FWIW I started with an RWMutex but it simplifies the code being a plain Mutex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.