-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Use regex cache to save memory #33147
Conversation
This functionality has been released in v5.14.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Description
Saves ~18% memory use by introducing a cache layer, regexache, between the code and
regexp.MustCompile()
. This de-duplicates regular expressions in memory. Althoughtregexache
can expired cache entries, testing so far seems to show the greatest reduction in memory use when the cache is not cleaned up (no expiration).To save memory, there may be a small performance hit from cache contention. This should be monitored to ensure it's not noticeable.
These are the results of profiling memory with and without
regexache
.regexache
regexache
, no expirationregexache
, 1s expiration, expiration protection at 2 uses, 5s interval, 0.5s clean per intervalregexache
, 0.5s expiration, expiration protection at 10 uses, 1s interval, 0.1s clean per intervalregexache
, 2s expiration, expiration protection at 3 uses, 2s interval, 0.1s clean per intervalRelations
Relates #32289
References
Output from Acceptance Testing