importer: reuse pluralize client to improve performance#5338
Open
wuxu92 wants to merge 5 commits intohashicorp:mainfrom
Open
importer: reuse pluralize client to improve performance#5338wuxu92 wants to merge 5 commits intohashicorp:mainfrom
importer: reuse pluralize client to improve performance#5338wuxu92 wants to merge 5 commits intohashicorp:mainfrom
Conversation
jackofallops
requested changes
Apr 24, 2026
Member
jackofallops
left a comment
There was a problem hiding this comment.
Thanks @wuxu92 - I think we can get even more out of this by removing the mutex which I don't believe is necessary? (unless you have testing evidence to show it is?)
| pluralizeClient *pluralize.Client | ||
| once sync.Once | ||
| // pluralizeClient is not thread safe | ||
| mux sync.Mutex |
Member
There was a problem hiding this comment.
I believe this is actually thread safe, do you have evidence to the contrary? (Singular() and Plural() are "read-only" and don't have any internal state change to lock for, so should be fine?)
Collaborator
Author
There was a problem hiding this comment.
Updated, Thanks! it's safe as we only call Singular and Plural here.
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.
Community Note
Description
The current pluralize function initialize the client for every call, it caused huge unnecessary memory allocations and caused GC increased a lot. by simply reusing the client, we can reduce the allocation a lot and import faster.
below is a experiment on importing Compute@2025-04-01, the allocations of pluralize client decreased from
4121064 (33.7%)to9841 (0.1%)by this PR. and import time cost from 143s -> 117s.Not reuse pluralize client:
Reuse pluralize client:

PR Checklist