Repository navigation
perf(kml): make a document's layer names unique in linear time - #763
Conversation
layers_of compared each layer's name with every name before it, and tried the suffixes of a taken name from (2) each time: quadratic in a document's Folders, cubic when they share a name (opengeos#630). A set of the names taken and, for each name, the next suffix to try make the loop linear. Names are only ever added, so a suffix found taken stays taken, and a name's next search resumes after the last suffix it took: the layers get the same names, in the same order. Release CLI, terrio info: a 1,654-byte KMZ of 4,000 unnamed Folders takes 0.10 s (28.71 s before), 100,000 named Folders 2.08 s (24.61 s); the output is byte-identical before and after on both, on their plain KML documents, and on a document of 3,000 colliding names. Peak RSS grows by about 3 MiB for the set of names. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 35 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Code reviewBugs: None found. I checked the new Security: None. The change is pure in-memory string handling with no new input surface. Performance: None. Each generated name costs one hash insert, and each base name's suffix counter only moves forward, so total work is linear in the number of generated names. The Quality (nits, low confidence that they matter):
CLAUDE.md: AGENTS.md is the applicable guidance. The test name I posted no inline comments, because none of the findings above is worth anchoring to a line. The naming nit would need a rename across three lines, so a one-line suggestion block would not apply cleanly. Change sizeCompared with the base branch: the whole PR against main (merge base e78a5d8 to PR head 905a696).
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Code reviewI found no correctness bugs. The new loop gives the same names in the same order as the old scan. A name's next search resumes after the last suffix it took, and every suffix it skips is already taken, so resuming cannot change the result. The layer-0 case and the parent-before-child order also match the old code. I traced the new test's 15 expected names by hand against the algorithm and they agree. Bugs
Security
Performance
Quality
Test coverage
CLAUDE.md / AGENTS.md
Change sizeCompared with the base branch: the whole PR against main (merge base c31df7c to PR head c765164).
|
Pull requests no longer edit CHANGELOG.md (opengeos#765): the release pull request writes each version's section from the pull request descriptions. Restore the file to the merge base so this pull request no longer conflicts with others there.
|
Pull requests no longer edit |
Code reviewBugs: None found. I traced the new Security: None found. The change only touches in-memory name bookkeeping. Confidence: high. Performance: None found. Each suffix a base name tries is attempted at most once across all layers, so the work is linear in the number of layers. The per-duplicate Quality:
CLAUDE.md (AGENTS.md): Mostly compliant. The change adds a regression test, the identifiers describe behavior, and the PR records before/after measurements with byte-identical output. Nothing in the changed file needs an SPDX header or NOTICE entry. The PR's known limitation, that names are unique only within each document (not across a KMZ's linked layer documents), is pre-existing and documented. I could not compile or run the tests in this environment (no shell), so the "tests pass" claims in the PR body are unverified here. Change sizeCompared: the whole PR against main (merge base c31df7c to PR head 3d54f0e).
|
A KML or KMZ document's layer names are made unique in time linear in its Folders and Documents. It took time quadratic in them, and cubic when they shared a name (#630):
terrio infoon a 1,654-byte KMZ of 4,000 Folders without a name takes 0.10 s, where it took 28.7 s, and on one of 100,000 named Folders 2.1 s, where it took 24.6 s. The names are the same, in the same order:Folder,Folder (2),Folder (3), and so on.Closes #630.
Behaviour
layers_of(drivers/vector/kml.rs) made a document's layer names unique in two costly ways. It compared each layer's name with every name before it, and it tried a taken name's suffixes from(2)each time. That cost time quadratic in a document's Folders and Documents, and cubic when they share a name. It now keeps a set of the names taken and, for each name, the next suffix to try, so each layer finds its name in constant expected time.(2),(3), and so on..kmlfiles (parse_styled), and KMZ archives (kmz_styled) for the main document and each layer document.Before and after
Release CLI,
terrio info, measured with/usr/bin/time -vwith nothing else heavy running. The CLI was built from e78a5d8 (before) and from this branch (after). The table gives one run before and the median of three runs after..kmlfile.kmlfile.kmlterrio infoprints the same output before and after for all five documents (72,001, 1,800,001, 72,001, 1,800,001 and 54,001 lines), layer names and their order included.a (2)andFolder (5)that a suffix would also produce.roads(KMZ): the CLI built from e78a5d8 had not finished after 586 s, when it was stopped, and this branch's took 3.2 s. Each laterroadssearched the suffixes from(2)again, against every earlier layer.Tests and mutations
layer_names_are_made_unique_in_document_order(new, in thekml.rsunit tests) reads one document as KML and as KMZ, and asserts the full list of its 15 layer names.Folder (3), which a later unnamed Folder must skip;Folder (2)given after the generated one, which must becomeFolder (2) (2).Mutations, each applied to the change and run against the test:
roads (1),Folder (1)roads (3),Folder (3) (3)Folder (2)twiceFolder (3)twiceFolder, and the first becomesdoc (2)(2), as before the changeChecks run
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningscargo test -p terrio --lib drivers::vector::kml::: 17 passedcargo test -p terrio --no-fail-fast: 3043 passed, 54 ignoredpre-commit runon the changed filesLimitations
doc.kmlholds a Folderroads, and a link namedroadsto a layer document, gives two layers namedroads, before and after this change.Summary by CodeRabbit