-
Notifications
You must be signed in to change notification settings - Fork 1k
[labs/ssr-client] Add digest cache #5074
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
Conversation
🦋 Changeset detectedLatest commit: 6a1a879 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| const digestSize = 2; | ||
|
|
||
| // Digest cache | ||
| const digestCache = new WeakMap<TemplateStringsArray, string>(); |
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.
Let's make sure that we're not exacerbating the static template memory leak with this...
I think we're not because once the static template cache frees a template, the forged TemplateStringsArray will be able to be freed and this cache will release the entry.
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.
I believe you're correct based on my understanding of how WeakMaps work in JS
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.
Once an object used as a key has been collected, its corresponding values in any WeakMap become candidates for garbage collection as well — as long as they aren't strongly referred to elsewhere.
-MDN
So as long as the template is only associated with WeakMaps (or I'm assuming other "weak" data structures), we should be good.
Co-authored-by: Justin Fagnani <[email protected]>
| // for `Buffer` from Node's built-in `buffer` module in our Rollup config (see | ||
| // note at the top of this file), and use that. | ||
| return NODE_MODE ? Buffer.from(str, 'binary').toString('base64') : btoa(str); | ||
| digest = NODE_MODE |
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.
btw, we should start using btoa in Node soon...
justinfagnani
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.
awesome!
This PR adds a cache for previously computed digest results. This should improve throughput when rendering the same
TemplateResultmultiple times.