From c856c8c02e10214b7dcbc937c2250c2e28318ab7 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 7 Nov 2026 10:27:38 -0800 Subject: [PATCH] linesweeper: each segment's horizontal decomposition takes 288 bytes instead of 824 AlmostHorizontalDecomposition stored its pieces in an ArrayVec of six CubicParams, so every decomposition took 824 bytes, and Segments keeps one for every segment, horizontal ones included. It now stores them in a SmallVec with two pieces inline (288 bytes); a decomposition with more pieces goes on the heap. For a closed polygon of 200,000 lines, the peak heap of Topology::from_path plus contours goes from 500.9 MB to 360.4 MB, with the same contours. README.craft.md gets a Local changes row, and SOURCE.json gets a local_patches entry and the new hash of src/curve/mod.rs. --- vendor/linesweeper/README.craft.md | 22 ++++++++----- vendor/linesweeper/SOURCE.json | 6 ++-- vendor/linesweeper/src/curve/mod.rs | 48 +++++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/vendor/linesweeper/README.craft.md b/vendor/linesweeper/README.craft.md index f683ca53de..491963318b 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -1,15 +1,23 @@ # Local linesweeper 0.5.0 copy -This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and no -file changed. `.cargo_vcs_info.json` names the commit it was packaged from, +This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and the +changes listed under Local changes. `.cargo_vcs_info.json` names the commit it was packaged from, `824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest names, which is archived; its README says development moved off GitHub. -Every file here except this one and `SOURCE.json` is byte for byte the file in the `.crate` archive. -`SOURCE.json` records the hash of the `.crate` download (`source_archive_sha256`) and, for every file -kept, the hash in the package (`source_sha256`) and the hash here (`sha256`). `upstream_repository` is -null because no public repository this copy can name holds `upstream_revision`. `local_patches` is -empty. +Every file here except this one, `SOURCE.json` and the files under Local changes is byte for byte the +file in the `.crate` archive. `SOURCE.json` records the hash of the `.crate` download +(`source_archive_sha256`) and, for every file kept, the hash in the package (`source_sha256`) and the +hash here (`sha256`). `upstream_repository` is null because no public repository this copy can name +holds `upstream_revision`. `local_patches` describes each local change. + +## Local changes + +| Change | Code comment label | Touches | Tests | +|---|---|---|---| +| `AlmostHorizontalDecomposition` stores up to two pieces inline in a `SmallVec` instead of six in an `ArrayVec`, which takes it from 824 to 288 bytes; `Segments` keeps one for every segment | `Craft patch (inline pieces)` | `src/curve/mod.rs` | `curve::test::horizontal_decomposition_stores_two_pieces_inline`, `curve::test::horizontal_decomposition_keeps_every_piece` | + +Every change here updates this table and `SOURCE.json` in the same commit. `omitted_files` lists the 43 files of the package left out here, with their hashes: diff --git a/vendor/linesweeper/SOURCE.json b/vendor/linesweeper/SOURCE.json index 9c71e51add..146431bcb1 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -7,7 +7,9 @@ "upstream_repository": null, "upstream_revision": "824b0791a750f7b27b8edcbb6c6244d0e629875e", "upstream_directory": "", - "local_patches": [], + "local_patches": [ + "In `src/curve/mod.rs`, `AlmostHorizontalDecomposition` stores its pieces in a `SmallVec<[CubicParams; 2]>` instead of an `ArrayVec`, so a decomposition takes 288 bytes instead of 824 and one with more than two pieces goes on the heap. `Segments` keeps one decomposition for every segment, horizontal ones included. For a closed polygon of 200,000 lines, the peak heap of `Topology::from_path` plus `contours` went from 500.9 MB to 360.4 MB with the same contours. `curve::test::horizontal_decomposition_stores_two_pieces_inline` covers the size and `curve::test::horizontal_decomposition_keeps_every_piece` covers decompositions of one, two and five pieces." + ], "files": [ { "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" }, { "path": ".gitignore", "source_sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0", "source_git_blob": null, "sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0" }, @@ -32,7 +34,7 @@ { "path": "proptest-regressions/topology.txt", "source_sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19", "source_git_blob": null, "sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19" }, { "path": "src/arbitrary.rs", "source_sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750", "source_git_blob": null, "sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750" }, { "path": "src/curve/line.rs", "source_sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e", "source_git_blob": null, "sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e" }, - { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2" }, + { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "02711a9662e1b5bea412a59cfe420ada1eca0bc685e0d6284c1b03875aa74165" }, { "path": "src/curve/split_quad.rs", "source_sha256": "b8aae4ce7c16fa623724f667e1058130a9c7eed693b5b01e8b9e16632b8ec45f", "source_git_blob": null, "sha256": "b8aae4ce7c16fa623724f667e1058130a9c7eed693b5b01e8b9e16632b8ec45f" }, { "path": "src/curve/transverse.rs", "source_sha256": "be9c695531f4cb0fe73af13e78040b51b9476c193d84562e701aadd07b3fd06e", "source_git_blob": null, "sha256": "be9c695531f4cb0fe73af13e78040b51b9476c193d84562e701aadd07b3fd06e" }, { "path": "src/generators.rs", "source_sha256": "cc9f2441546db9204219294c354449809dda77dffad06fec8a30f45df01e6fef", "source_git_blob": null, "sha256": "cc9f2441546db9204219294c354449809dda77dffad06fec8a30f45df01e6fef" }, diff --git a/vendor/linesweeper/src/curve/mod.rs b/vendor/linesweeper/src/curve/mod.rs index f602308573..05637d41aa 100644 --- a/vendor/linesweeper/src/curve/mod.rs +++ b/vendor/linesweeper/src/curve/mod.rs @@ -1390,7 +1390,10 @@ fn intersect_cubics_rec( /// A decomposition of a cubic Bezier into almost-horizontal and not-almost-horizontal pieces. #[derive(Clone, Debug, Default)] pub struct AlmostHorizontalDecomposition { - pieces: ArrayVec, + // Craft patch (inline pieces): up to two pieces are stored inline and more + // go on the heap. `Segments` stores one decomposition per segment, so this + // size is paid for every segment of the input. + pieces: SmallVec<[CubicParams; 2]>, } impl AlmostHorizontalDecomposition { @@ -1447,7 +1450,7 @@ impl AlmostHorizontalDecomposition { let mut last_y = c.p0.y; let mut last_end = 0.0; let orig_c = c; - let mut ret = ArrayVec::default(); + let mut ret: SmallVec<[CubicParams; 2]> = SmallVec::new(); for (_, end, order) in subdivision.iter(0.0) { let start = last_end; // If there's no actual subdivision, skip the subsegment operation. @@ -1952,6 +1955,47 @@ mod test { ); } + // Craft patch (inline pieces) tests: a decomposition is no larger than two + // inline pieces, and one with more pieces than that keeps all of them. + #[test] + fn horizontal_decomposition_stores_two_pieces_inline() { + assert!( + std::mem::size_of::() + <= 2 * std::mem::size_of::() + 2 * std::mem::size_of::() + ); + } + + #[test] + fn horizontal_decomposition_keeps_every_piece() { + let cases = [ + ( + CubicBez::new((0.0, 0.0), (10.0, 10.0), (20.0, 20.0), (30.0, 30.0)), + 1, + ), + ( + CubicBez::new((0.0, 0.0), (10.0, 10.0), (20.0, 20.0), (500.0, 30.0)), + 2, + ), + ( + CubicBez::new((0.0, 0.0), (2000.0, 10.0), (-1000.0, 20.0), (1000.0, 30.0)), + 5, + ), + ( + CubicBez::new((0.0, 0.0), (2000.0, 0.0), (-1000.0, 30.0), (1000.0, 30.0)), + 5, + ), + ]; + for (c, count) in cases { + let decomp = AlmostHorizontalDecomposition::from_monotone_cubic(c); + assert_eq!(decomp.pieces.len(), count); + assert_eq!(decomp.pieces[0].c.p0, c.p0); + assert_eq!(decomp.pieces[count - 1].c.p3, c.p3); + for pair in decomp.pieces.windows(2) { + assert_eq!(pair[0].c.p3.y, pair[1].c.p0.y); + } + } + } + // This test recurses a bit too deeply. The two curves are quite close, // and near the end they're just a bit more than eps apart. #[test]