Skip to content

Consolidate bundled-data loading behind compression helpers#693

Merged
Boshen merged 1 commit into
mainfrom
compression-helpers
May 29, 2026
Merged

Consolidate bundled-data loading behind compression helpers#693
Boshen merged 1 commit into
mainfrom
compression-helpers

Conversation

@Boshen

@Boshen Boshen commented May 29, 2026

Copy link
Copy Markdown
Member

Every compressed blob was loaded with ad-hoc OnceLock + inline postcard::from_bytes(&decompress_deflate(include_bytes!(…))) boilerplate — repeated and slightly varied across ~10 call sites plus the two generated loaders. This consolidates them behind three small helpers in compression.rs:

  • LazyData<T> — a blob decompressed + postcard-deserialized into T on first use and cached. For values consumed as-is: the feature/region version tables, the per-browser version order, and the generated key tables.
  • LazyBlob — a blob decompressed to raw bytes and cached, for data decoded by hand at the use site (the byte-plane and run-length blobs, where a generic deserializer would bloat the binary).
  • load<T> — one-shot decompress + deserialize, shared by LazyData and by the few sites that transform the decoded value further (node versions, the browser map, the region pair table).

Call sites lose their hand-written accessor functions and become uniform static X: LazyData<…> = LazyData::new(include_bytes!(…)) / X.get(). The remaining OnceLocks now cache only derived/transformed values (e.g. the browser FxHashMap, version aliases), and their blob loads route through load().

No data/behavior change, small size win

Blobs are byte-identical (regenerated). Sharing the loaders de-duplicates the per-site monomorphized closures, so the musl inspect example drops 764,160 → 761,920 B (−2,240). All tests and the JS-equivalence proptests pass.

🤖 Generated with Claude Code

All compressed blobs were loaded with ad-hoc `OnceLock` + inline
`postcard::from_bytes(&decompress_deflate(include_bytes!(...)))` boilerplate,
repeated (and slightly varied) across ~10 sites plus the generated loaders.
Introduce three small helpers in `compression.rs` and route every site through
them:

- `LazyData<T>`: a blob decompressed + postcard-deserialized into `T` on first
  use and cached. Used where the value is consumed as-is (version tables,
  per-browser version order, generated key tables).
- `LazyBlob`: a blob decompressed to raw bytes and cached, for data decoded by
  hand at the use site (the byte-plane and run-length blobs).
- `load<T>`: one-shot decompress + deserialize, shared by `LazyData` and by the
  few sites that transform the decoded value further (node versions, the
  browser map, the region pair table).

This removes the per-site accessor functions and unifies the idiom; the
remaining `OnceLock`s cache only derived/transformed values. No data or
behavior change (blobs are byte-identical); musl `inspect` example
764,160 -> 761,920 B as the shared helpers de-duplicate the per-site loaders.
@codspeed-hq

codspeed-hq Bot commented May 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing compression-helpers (70dcdc3) with main (14a746a)

Open in CodSpeed

@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.81%. Comparing base (14a746a) to head (70dcdc3).

Files with missing lines Patch % Lines
src/data/caniuse/compression.rs 60.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #693      +/-   ##
==========================================
- Coverage   99.06%   98.81%   -0.26%     
==========================================
  Files          47       47              
  Lines        2456     2443      -13     
==========================================
- Hits         2433     2414      -19     
- Misses         23       29       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Boshen Boshen merged commit bde46e1 into main May 29, 2026
16 checks passed
@Boshen Boshen deleted the compression-helpers branch May 29, 2026 14:33
@oxc-guard oxc-guard Bot mentioned this pull request May 29, 2026
Boshen pushed a commit that referenced this pull request May 29, 2026
## 🤖 New release

* `oxc-browserslist`: 3.0.3 -> 3.0.4 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[3.0.4](oxc-browserslist-v3.0.3...oxc-browserslist-v3.0.4)
- 2026-05-29

### Other

- DRY up feature/region codegen with shared table + lookup helpers
([#694](#694))
- Consolidate bundled-data loading behind compression helpers
([#693](#693))
- Reduce binary size: run-length encode feature support versions
([#692](#692))
- Reduce binary size: Zopfli codegen compression + percentage byte-plane
([#691](#691))
- Reduce binary size: byte-plane (stream-split) compression for region
pair indices
([#690](#690))
- Update README binary size to 621K
([#689](#689))
- Reduce binary size of bundled caniuse/electron data
([#688](#688))
- Switch codegen data source from caniuse-db to caniuse-lite
([#687](#687))
- Update browserslist
([#685](#685))
- Update rust crates
([#682](#682))
- Update browserslist
([#679](#679))
- Update browserslist
([#678](#678))
- Update browserslist
([#677](#677))
- Update browserslist
([#673](#673))
- Update browserslist
([#671](#671))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: oxc-guard[bot] <276638029+oxc-guard[bot]@users.noreply.github.com>
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