Repository navigation
🐛 fix(xpath): keep nested predicates linear in pinned nodes - #2179
Conversation
Before each call into Python, the pinning hook paired every live frame with the frames it held by scanning them all, and looked every newly pinned node up in each held frame's map. Nested predicates and operators paid the nesting depth again per frame and per pinned node. Once the live frames first reach 16, the evaluation indexes every frame's pins by node and pairs the frames in one pass, until it ends. Shallower expressions keep the per-frame lookup unchanged. Fixes tox-dev#1748
Merging this PR will improve performance by 6.99%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
XPath expressions that call into Python, such as
matches(),replace(),re:test()or an extension function, got slower with every level of nesting. Nested predicates over a large document could make one evaluation take several times as long as its flat form, and the cost grew with the nesting rather than the document. 🚀 Once this merges, nested expressions stay fast, and the cost no longer climbs with the nesting. Fixes #1748.Before each call into Python, the engine hands out a wrapper for every node the evaluation holds, and it used to look each new node up in every live frame. Once an evaluation holds enough frames, the engine builds one index of those nodes and keeps it until the evaluation ends, so a new node costs one lookup. Shallow expressions keep the per-frame path.
Behavior changes
None. Results, errors and the wrappers handed to Python are the same. Only the cost of nested expressions that call into Python changes.