Repository navigation
Improve performance when scanning long lines with many [ characters - #20694
Conversation
[Medium impact] The PR appears safe to merge; no actionable issues were found. Reviews (2) · Last reviewed commit: "Share work between the machines that ext..." · Reviewed by Greptile |
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
On a `<` or an uppercase letter, the candidate machine searches the rest of the line for a valid before boundary character. If it finds none, it restarts at the next character, and searches the same bytes again. Thus a long line of these characters without a boundary (e.g. `AAAA…` or `<<<<…`) takes quadratic time. The machine now remembers the position from which the line has no boundary, and a later search stops there. This position only depends on the input, so the machine keeps it when it resets.
When the main candidate machine consumes a range, the extractor starts a new candidate machine after each `[` in that range, to find the candidates inside the brackets. Each machine runs until the end of the range. Thus a long line with many `[` (e.g. `[[[[…`, `a-[a-[…` or minified JSON) takes quadratic time. The candidate machine can now report each position where it starts from a clean state (no variant in progress). From such a position, the machine finds the same candidates, no matter where it started. Thus when a machine reaches a position where an earlier machine of the same range was in a clean state, it stops: the earlier machine already found the candidates from there. The machines of a line also share one `CandidateMachine`, so that they find the position from which the line has no boundary only once. The extracted candidates do not change.
d057c05 to
db94c8a
Compare
… act on (#20728) This PR keeps `### Changed` in the changelog for changes that users may have to act on, and documents which section to use. `[Unreleased]` had a `### Changed` section with two performance entries (#20680 and #20688). A performance improvement is not a change that users have to act on, and the repo already lists them under `### Fixed` (e.g. #20694, #20678 and #20663). ## Changes - `CHANGELOG.md`: remove the `### Changed` section of `[Unreleased]`. Combine the two entries into one entry in `### Fixed`, because #20688 only extends #20680 to the other integrations. The entry goes in the merge order of #20680. - `CHANGELOG.md`: move the canonicalization entry of #20697 from `### Added` to `### Fixed`, in merge order, and drop the empty `### Added` heading. A canonicalization improvement is not a new feature for users, and the canonicalization entries of 4.3.4 and 4.3.5 are in `### Fixed` too. - `.github/CONTRIBUTING.md`: add a guide on which section to pick. The examples for `### Changed` come from earlier releases: changes to the CSS of existing utilities, renamed or replaced utilities (also when the upgrade tool migrates them), theme defaults, APIs, stricter parsing, source detection defaults, and supported versions. - `.changelog/README.md`: link to that guide. This PR edits `CHANGELOG.md` directly instead of adding a fragment, because it fixes entries that the "Compile changelog" workflow already compiled. Released sections stay as they are. The PR changes only docs, so it needs no changelog entry of its own. ## Test plan - `pnpm changelog check` passes. - `pnpm --silent changelog` shows `[Unreleased]` with only `### Fixed`. - `pnpm prettier --check` passes for the three files.
Summary
The Oxide extractor took quadratic time on some long lines. Minified files and generated content often have long lines, so this can slow down the scan of a real project. For example, on
main, a line of 80 KB with only[characters takes 3.2 s.There are two causes:
[in that range, to find the candidates inside the brackets (e.g.[ClassPrefix('gap-y-4')]). Each machine runs until the end of the range. Thus a long line with many[takes quadratic time.<or an uppercase letter, the candidate machine searches the rest of the line for a boundary character. If the line has none, the machine restarts at the next character, and searches the same bytes again.This PR fixes both, and the extracted candidates do not change:
Times for one line of 80 KB, with an optimized build:
main[repeateda-[repeated"a-['repeateda-[a]-[a]…<%= a-[repeatedTest plan
test_long_lines_without_candidates. It checks that long lines of these shapes give no candidates, and that each line takes less than 5 s. Onmain, the first line alone takes 89 s in a debug build. With this PR, the full test takes about 0.5 s.test_overlapping_candidates_in_long_lines. It checks the candidates in nested arrays on a long line (e.g. minified JSON).main. They are the same for:node_modules, with many minified bundles and source maps. On the same lines, the total time went from 23.1 s to 20.2 s.[,],\, quotes,hover:,bg-[and[&.cargo testincrates/oxide,pnpm run build, andvitestpass.Sent by an AI assistant on behalf of @RobinMalfait.