Skip to content

[js] Reduce GC pressure in TypeScript getAttribute and isDisplayed atoms#17582

Merged
AutomatedTester merged 3 commits into
trunkfrom
worktree-ts-atom-perf
May 28, 2026
Merged

[js] Reduce GC pressure in TypeScript getAttribute and isDisplayed atoms#17582
AutomatedTester merged 3 commits into
trunkfrom
worktree-ts-atom-perf

Conversation

@AutomatedTester
Copy link
Copy Markdown
Member

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

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s):
    • What was generated:
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

🔄 Types of changes

  • Cleanup (formatting, renaming)
  • Bug fix (backwards compatible)
  • New feature (non-breaking change which adds functionality and tests!)
  • Breaking change (fix or feature that would cause existing functionality to change)

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.
@selenium-ci selenium-ci added the B-atoms JavaScript chunks generated by Google closure label May 27, 2026
…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.
@AutomatedTester AutomatedTester merged commit d850933 into trunk May 28, 2026
65 of 66 checks passed
@AutomatedTester AutomatedTester deleted the worktree-ts-atom-perf branch May 28, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-atoms JavaScript chunks generated by Google closure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants