-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(schema-compiler): Use LRU for CompilerCache to reduce memory usage #10247
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
base: master
Are you sure you want to change the base?
Conversation
- Replace nested object structure with Map<string, any> - Use JSON.stringify for composite keys - Consistent approach with CompilerCache
| * @returns Returns the result of executing a function (Either call a function or take a value from the cache) | ||
| */ | ||
| public cache(key: any[], fn: Function): any { | ||
| let keyHolder = this.storage; |
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.
// For key ['a', 'b', 'c']:
// storage['a'] = {}
// storage['a']['b'] = {}
// storage['a']['b']['c'] = fn()
I don't know the reason (I assume, string interning) for writing such a nested cache, but I am certain that it's better to rewrite it. I've done fastComputeCacheKey and tested that it's using ConsString
- Add computeCacheKey function using V8 ConsString optimization - String concatenation (+=) is ~3x faster than JSON.stringify - Handle string/number directly, fallback to JSON.stringify for objects - Support both array keys and unknown key types
KSDaemon
left a comment
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.
🔥
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #10247 +/- ##
===========================================
- Coverage 83.25% 55.12% -28.14%
===========================================
Files 247 221 -26
Lines 74259 17128 -57131
Branches 0 3505 +3505
===========================================
- Hits 61826 9442 -52384
+ Misses 12433 7187 -5246
- Partials 0 499 +499
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Memory improvements:
storage['a']['b']['c']that could grow unbounded) for cleaner storagePerformance optimization: