Skip to content
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

feat: make Lipgloss Style thread-safe (mutex) #141

Closed
wants to merge 1 commit into from
Closed

Conversation

muesli
Copy link
Contributor

@muesli muesli commented Oct 5, 2022

This is related to #139, but uses a sync.RWMutex based approach to fully guard the Style struct.

Since we had a few reports about concurrently accessing base style definitions, I figured one solution would be making Style's rules map thread-safe. While it's an elegant solution, it is a trade-off: it guards against crashes from concurrent access, but that obviously slows down access by a tiny bit. I don't think the impact is too bad, though, and not crashing is always nice.

go test -bench=. -benchtime=30s

Before change:

goos: linux
goarch: amd64
pkg: github.com/charmbracelet/lipgloss
cpu: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
BenchmarkStyleRender-4           7875594              4555 ns/op
PASS

With sync.RWMutex:

goos: linux
goarch: amd64
pkg: github.com/charmbracelet/lipgloss
cpu: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
BenchmarkStyleRender-4           5798413              6138 ns/op
PASS

@muesli muesli added the enhancement New feature or request label Oct 5, 2022
@muesli muesli force-pushed the style-mutex branch 2 times, most recently from 1db7974 to 9ec9062 Compare October 6, 2022 09:05
aymanbagabas added a commit that referenced this pull request Mar 28, 2024
Use an int to store property existence and style struct fields to store
the actual values for each non-bool property.

Fixes: #139
Fixes: #141
aymanbagabas added a commit that referenced this pull request Mar 28, 2024
Use an int to store property existence and style struct fields to store
the actual values for each non-bool property.

Fixes: #139
Fixes: #141
aymanbagabas added a commit that referenced this pull request Mar 28, 2024
Use an int to store property existence and style struct fields to store
the actual values for each non-bool property.

Fixes: #139
Fixes: #141
aymanbagabas added a commit that referenced this pull request May 2, 2024
Use an int to store property existence and style struct fields to store
the actual values for each non-bool property.

Fixes: #139
Fixes: #141
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants