-
Notifications
You must be signed in to change notification settings - Fork 5
perf: cache color conversion #43
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
Conversation
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.
Pull Request Overview
A PR to improve the performance of color conversion by caching its results.
- Introduces a package-level cache using a map to store conversion results.
- Modifies the Convert method to check for cached values and memoize new conversions.
- Adds concurrency control using sync.Once and sync.Mutex to protect cache access.
6cad6e0
to
490213b
Compare
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.
Pull Request Overview
This PR introduces a caching mechanism to speed up color conversion by storing already computed conversion results.
- Added a global cache map along with sync.Once and sync.Mutex for initializing and accessing the cache concurrently.
- Updated the Convert method to check and store conversion results to improve performance in frequently used color conversion scenarios.
490213b
to
36569d7
Compare
This speeds up color conversion by caching the results of color conversion. Since for each colorprofile, the conversion is the same for each color, we can cache the results of the conversion to improve performance. This is currently noticeable when you run Bubble Tea v2 examples like `examples/splash`, `examples/space`, and `examples/doom-fire` with a profile that needs conversion. ```go COLORTERM= TERM=xterm go run ./splash ```
36569d7
to
6117e86
Compare
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.
Pull Request Overview
This PR introduces a caching mechanism to speed up color conversion by storing previously computed conversions.
- Added a global cache and mutex to handle concurrent access
- Updated the Convert method to check and update the cache
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.
Pull Request Overview
This PR improves performance by caching the results of color conversion to reduce redundant computations, particularly for profiles requiring conversion.
- Introduces a global cache variable and a read/write mutex for safe concurrent access.
- Refactors the Convert function to first check for a cached value and then, using a deferred block, cache the conversion result if not previously stored.
Comments suppressed due to low confidence (1)
profile.go:55
- [nitpick] Consider renaming the return variable 'cc' to a more descriptive name like 'convertedColor' to improve code clarity.
func (p Profile) Convert(c color.Color) (cc color.Color) {
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.
Pull Request Overview
This PR improves performance in color conversion by caching conversion results for each color profile. Key changes include updates to test cases and types in profile_test.go, the addition of a dedicated caching test, and modifications to the Convert method in profile.go to implement caching.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
profile_test.go | Updated tests to reflect new types and added a caching test. |
profile.go | Refactored the Convert method to include caching logic and removed obsolete conversion code. |
Files not reviewed (1)
- go.mod: Language not supported
Comments suppressed due to low confidence (1)
profile.go:52
- [nitpick] Consider using a more descriptive name than 'cc' (e.g., 'convertedColor') to improve code readability.
func (p Profile) Convert(c color.Color) (cc color.Color) {
e46a2c5
to
efbeb2f
Compare
This speeds up color conversion by caching the results of color conversion. Since for each colorprofile, the conversion is the same for each color, we can cache the results of the conversion to improve performance.
This is currently noticeable when you run Bubble Tea v2 examples like
examples/splash
,examples/space
, andexamples/doom-fire
with a profile that needs conversion.