Skip to content

🐛 fix(xpath): keep many-argument calls linear - #2156

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/y2r6t0lb
Nov 15, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:sec-fix/y2r6t0lb

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

An XPath expression that uses regex or Python extension functions took time that grew with the product of a call's argument count and the nodes in its arguments. 📈 Each stored argument made the next pin visit every node of the earlier arguments again. Expressions without such functions never pin and were not affected. After this change the cost grows with the argument count plus the node count, and results do not change.

Architecture

Before each Python call, the evaluator pins the nodes of live frames, so that a callback cannot free the nodes it holds. The frame's pin record now keeps how many results it has already pinned, and each pin visits only the results added since. The version counter that forced full revisits had no other reader, so it is gone.

Behavior changes

  • The pins still cover every node a frame holds when a callback runs.
  • An argument still being evaluated is no longer an empty slot to the pin hook. The frames of that evaluation pin their own nodes as they are created.

Fixes #1778.

A function call that runs a regex or extension function pins the nodes
every live frame holds before each comparison, so that the callbacks
cannot free them. The call bumped its frame version after each stored
argument, so the next pin took the frame for a new one and walked every
argument again. A call with many arguments and many nodes in the first
one then cost the product of the two counts.

Pin only the results added since the last visit, and drop the version
counter that only the argument loop read. Each argument is visited once,
so the cost grows with the argument count plus the node count.

Fixes tox-dev#1778
@gaborbernat gaborbernat added the bug Something isn't working label Nov 15, 2026
@codspeed

codspeed Bot commented Nov 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 582 untouched benchmarks
⏩ 89 skipped benchmarks1


Comparing gaborbernat:sec-fix/y2r6t0lb (5b311b1) with main (127bfde)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@gaborbernat
gaborbernat merged commit 81d30e4 into tox-dev:main Nov 15, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XPath calls with many comparison arguments re-pin earlier nodes after every argument

1 participant