Skip to content

refactor: reuse pattern execution contexts - #1083

Merged
chubes4 merged 1 commit into
trunkfrom
refactor/reuse-pattern-context
Aug 23, 2026
Merged

refactor: reuse pattern execution contexts#1083
chubes4 merged 1 commit into
trunkfrom
refactor/reuse-pattern-context

Conversation

@chubes4

@chubes4 chubes4 commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • construct the normal, runtime-DOM-restricted, and probe PatternContext graphs once per HtmlTransformer
  • reuse those immutable service graphs across recognition attempts and sequential transforms
  • keep per-transform data in HtmlTransformerSession; cached closures continue resolving the current session through the transformer

This is a bounded maintainability/performance slice from #242. It removes repeated allocation of the full callback graph and PatternRecursiveConverter on every recognizePatterns() call while preserving the explicit normal/restricted/probe policy boundaries.

Behavior and performance proof

  • fresh and reused transformer instances produce identical patterned output across sequential transforms
  • staged dispatch and probe contracts remain green
  • five alternating baseline/candidate benchmark pairs over 1,500 nested-container transformations were faster in every pair
  • median elapsed time improved from 1319.6 ms to 1256.8 ms (4.8%)

The timing benchmark is external evidence rather than a brittle CI threshold.

Verification

  • composer test
  • 280 parity fixtures
  • package install proof

AI assistance

OpenAI GPT-5.6 Sol via OpenCode was used to trace context construction frequency and session capture semantics, implement constructor-owned context reuse, add reused-instance behavior coverage, benchmark against the merged baseline, and run verification. Chris Huber is responsible for every line.

@chubes4
chubes4 merged commit 0502939 into trunk Aug 23, 2026
4 checks passed
@chubes4
chubes4 deleted the refactor/reuse-pattern-context branch August 23, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant