[js] Reduce GC pressure in TypeScript getAttribute and isDisplayed atoms#17582
Merged
Conversation
getAttribute: convert BOOLEAN_PROPERTIES from Array to Set for O(1) .has()
lookup instead of O(n) .indexOf(), and call element.getAttribute(name)
directly at the three call sites that already hold the lowercased name,
avoiding a redundant .toLowerCase() in the wrapper.
isDisplayed: replace findImageUsingMap's full-DOM getElementsByTagName('*')
scan with a single querySelector('[usemap="#..."]') call, using the same
CSS attribute-value escaping pattern applied to nameMany in find-elements.
…d atom Add three per-call Maps inside isShownElement, scoped to the single synchronous invocation so there is no stale-data risk and no GC pressure between calls: - computedStyleCache: getEffectiveStyle now fetches getComputedStyle once per element and reuses the CSSStyleDeclaration for subsequent property reads. A typical isShown call queries 5-8 properties on the same element. - clientRectCache: getClientRect caches the Rect after the first getBoundingClientRect (or imageMap rect) computation. Overflow checking and positiveSize both query ancestor rects, so shared containers are only laid out once. - displayedCache: displayed() walks the full ancestor chain on every call. positiveSize iterates all children calling displayedFn on each, so shared ancestors were re-walked N times for N siblings. The cache makes each ancestor node free after the first traversal.
document.createElement('script').async returns true by default (browser
sets the 'force async' flag on script elements created via JS), so the
test expecting null was never correct. The absent-boolean-returns-null
behaviour is already covered by the existing disabled and readonly tests.
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.
getAttribute: convert BOOLEAN_PROPERTIES from Array to Set for O(1) .has() lookup instead of O(n) .indexOf(), and call element.getAttribute(name) directly at the three call sites that already hold the lowercased name, avoiding a redundant .toLowerCase() in the wrapper.
isDisplayed: replace findImageUsingMap's full-DOM getElementsByTagName('*') scan with a single querySelector('[usemap="#..."]') call, using the same CSS attribute-value escaping pattern applied to nameMany in find-elements.
🔗 Related Issues
💥 What does this PR do?
🔧 Implementation Notes
🤖 AI assistance
💡 Additional Considerations
🔄 Types of changes