Skip to content

perf: avoid repeated inline markup closing-marker scans - #68

Open
fullofcaffeine wants to merge 1 commit into
HaxeCheckstyle:masterfrom
fullofcaffeine:hxhx-agent/vz0h6-upstream-markup
Open

fullofcaffeine wants to merge 1 commit into
HaxeCheckstyle:masterfrom
fullofcaffeine:hxhx-agent/vz0h6-upstream-markup

Conversation

@fullofcaffeine

Copy link
Copy Markdown

perf: avoid repeated closing-marker searches in inline markup

Large Haxe files with many generic types can spend minutes in the formatter's markup lexer.
The lexer repeatedly scans the remaining text for the same closing markers while its cursor advances.

This patch keeps the next closing-tag and self-closing positions within each inlineMarkup call.
It searches again only after the cursor passes a found marker.
When both closing forms are absent, it immediately returns the ordinary less-than token.
The existing token decisions, nesting rules, and cursor updates remain in place.

On one 25,517-line C++ backend module, an unchanged formatter build exceeded 150 seconds; the candidate completed its check in 99 seconds.
These are operational results on a shared host, not a controlled benchmark.
The patch targets upstream master at 49db59c.
The affected lexer code is identical to the formatter's pinned parser version used for the timing comparison.

Validation:

  • 5,199 differential cases preserve complete token streams and byte offsets, including malformed markup and Unicode input.
  • Formatter v1.18.0: 1,831/1,831 assertions pass, including exact golden output and repeated formatting.
  • Parser tests on Haxe 4.3.7: 515/515 assertions pass, including 40 new focused assertions.
  • The parser's historical pinned nightly is unavailable through Lix; the formatter's own pinned compiler built both benchmark artifacts.
  • Existing Unicode markup start-offset behavior is unchanged and needs separate investigation.

Agent provenance

Prepared by the hxhx-local-identity-maintainer agent using GPT-6 while investigating task haxe_ocaml-vz0h6.
Repeated formatter timeouts blocked verification of a compiler fix, which led the agent to profile the parser dependency.
The agent retains responsibility for review fixes and rebasing; upstream maintainers control acceptance and merge.
Other agents should preserve this ownership unless the repository owner records a handoff.
No upstream compiler implementation was copied into hxhx; this patch edits the existing BSD-licensed parser dependency at its owner.

Large files with repeated generic types can make markup detection scan
the remaining source repeatedly. Remember the next closing markers while
the cursor advances, and return the less-than token when neither closing
form exists. Keep this state local to one markup scan.

Preserve the existing nesting decisions, token contents, and cursor
updates. Add focused tests for nested and adjacent markup, incomplete
input, and Unicode text followed by another token.

Validation includes 5,199 differential lexer cases, the formatter's
1,831 assertions, and the current parser's 515 assertions on Haxe 4.3.7.
The optimization does not repair the existing Unicode markup start
offset or change formatter rules. Full consumer adoption remains separate.
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