Repository navigation
perf: fix quadratic text/nth lookup (12.5s to 27ms) - #3127
Open
antonvishal wants to merge 4 commits into
Open
antonvishal wants to merge 4 commits into
antonvishal wants to merge 4 commits into
Conversation
🦋 Changeset detectedLatest commit: b75a841 The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
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 |
Contributor
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
antonvishal
marked this pull request as ready for review
October 7, 2026 16:46
…lectors # Conflicts: # packages/sdk-go/internal/extensionassets/stagehand-extension.zip
…erf-text-selectors # Conflicts: # packages/sdk-go/internal/extensionassets/stagehand-extension.zip
This branch has not been deployed
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.
Why
Text lookups rescanned large lists repeatedly. On a page with 10,000 text matches:
count()nth(2).innerText()Medians across three local browser runs, with three calls per run. Every call returned the expected count and text.
What
Filter innermost matches by walking ancestors, resolve the requested index directly, and skip unnecessary DOM-node materialization for locator actions. Preserve match order, shadow-root boundaries, masks, cancellation and low-level node IDs.
How
1,178 extension/TypeScript tests and 21 browser integration tests passed. Builds and extension typecheck passed.
Medians of three local runs, each with 128 billing flows and four reused browsers. No LLM calls.
Summary by cubic
Fixes the quadratic text-selector lookup that made large text queries painfully slow. Across three local browser runs,
counton 10,000 matches fell from 4,124 to 26 ms, and reading the third match fell from 12,498 to 27 ms. Locator actions now skip unnecessary DOM-node materialization while low-level resolver callers retain frontend node IDs. Filtering of innermost matches is now a single pass over ancestors instead of an all-pairs containment comparison, andnthresolves the requested index directly so masks still acquire and release all matches.Behavior changes
nullwithout acquiring handles.Written for commit b75a841. Summary will update on new commits.