-
Notifications
You must be signed in to change notification settings - Fork 733
Pool collators in LS #1582
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
Pool collators in LS #1582
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ import ( | |||||||||||||
| "github.com/microsoft/typescript-go/internal/scanner" | ||||||||||||||
| "github.com/microsoft/typescript-go/internal/stringutil" | ||||||||||||||
| "golang.org/x/text/collate" | ||||||||||||||
| "golang.org/x/text/language" | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| func (l *LanguageService) ProvideCompletion( | ||||||||||||||
|
|
@@ -2980,6 +2981,25 @@ func getCompletionsSymbolKind(kind ScriptElementKind) lsproto.CompletionItemKind | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| var collatorCache collections.SyncMap[language.Tag, *sync.Pool] | ||||||||||||||
|
|
||||||||||||||
| func getCollator(tag language.Tag) *collate.Collator { | ||||||||||||||
| pool, ok := collatorCache.Load(tag) | ||||||||||||||
| if !ok { | ||||||||||||||
| pool, _ = collatorCache.LoadOrStore(tag, &sync.Pool{ | ||||||||||||||
| New: func() any { | ||||||||||||||
| return collate.New(tag) | ||||||||||||||
| }, | ||||||||||||||
| }) | ||||||||||||||
| } | ||||||||||||||
| return pool.Get().(*collate.Collator) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func putCollator(tag language.Tag, collator *collate.Collator) { | ||||||||||||||
| pool, _ := collatorCache.Load(tag) | ||||||||||||||
|
||||||||||||||
| pool, _ := collatorCache.Load(tag) | |
| pool, _ := collatorCache.LoadOrStore(tag, &sync.Pool{ | |
| New: func() any { | |
| return collate.New(tag) | |
| }, | |
| }) |
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.
Suggested code is wrong because it'll just waste loads and loads of allocs. If I wanted to solve this, I'd just return a done func from get.
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.
Why is this a
LoadOrStoreinstead of just aStore?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.
Otherwise two callers would update totally different maps