-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: store getComputedStyle result to avoid redoing that work #1048
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3ef12df
feat: store getComputedStyle result to avoid redoing that work
TomPridham 93075c8
fix: use a caching version of getComputedStyles instead of passing mu…
TomPridham 8ea82e3
fix: run format
TomPridham 7c78f49
fix: lint errors
TomPridham 4eee4b6
fix: make it clear when using uncached vs cached version, dont cache …
TomPridham ee90051
fix: remove map polyfill completely so avoid accidental uses
TomPridham b20d2d0
fix: add Map type stub back in with note about not including an actua…
TomPridham f2b6eb5
clean git diff
eps1lon 109ccbd
Add changesetr
eps1lon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"dom-accessibility-api": minor | ||
--- | ||
|
||
Cache `window.getComputedStyle` results | ||
|
||
Should improve performance in environments that don't cache these results natively e.g. JSDOM. | ||
This increases memory usage. | ||
If this results in adverse effects (e.g. resource constrained browser environments), please file an issue. |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
declare global { | ||
class Map<K, V> { | ||
// es2015.collection.d.ts | ||
clear(): void; | ||
delete(key: K): boolean; | ||
forEach( | ||
callbackfn: (value: V, key: K, map: Map<K, V>) => void, | ||
thisArg?: unknown, | ||
): void; | ||
get(key: K): V | undefined; | ||
has(key: K): boolean; | ||
set(key: K, value: V): this; | ||
readonly size: number; | ||
} | ||
} | ||
|
||
// we need to export something here to make this file a module, but don't want to | ||
// actually include a polyfill because it's potentially significantly slower than | ||
// the native implementation | ||
export {}; |
Oops, something went wrong.
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.
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.
Worth calling out that this lookup is not the expected O(1) but O(N) which is especially important since this may negate any benefit we get for caching.
I feel like we should only cache when the built-in
Map
is available. If you're testing in IE11, you don't need the caching anyway since you're in a browser already which has less issues with computing styles.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.
that makes sense. i left a comment in the
getComputedStyles
function about the polyfill being slower. let me know if you want me to document that somewhere else as wellThere 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'm saying we shouldn't use the polyfill at all and only cache when we know the lookup is O(1).
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.
sorry, i should have been clearer. i left a comment saying it was slower and that was why we were skipping using the caching if
Map
is undefinedThere 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 just removed the polyfill completely so there won't be a chance someone stumbles into the slow behavior
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 did end up having to include the global type for Map because otherwise TS complained about needing to change the target