Skip to content

DRY up feature/region codegen with shared table + lookup helpers#694

Merged
Boshen merged 1 commit into
mainfrom
codegen-dry
May 29, 2026
Merged

DRY up feature/region codegen with shared table + lookup helpers#694
Boshen merged 1 commit into
mainfrom
codegen-dry

Conversation

@Boshen

@Boshen Boshen commented May 29, 2026

Copy link
Copy Markdown
Member

The feature and region data generators each hand-rolled the same two patterns, which had drifted apart over time:

  1. Version-string intern tableBTreeSet → sorted Vec<String> → value→index map → save blob.
  2. Keys blob + lookup function — save a _keys.bin and emit a binary-search accessor. These had become inconsistent: the feature one used match + static RANGES, the region one used .ok()? + const RANGES.

This extracts two shared helpers in xtask utils:

  • intern_table(blob, values) — dedup + lexicographically sort into a table, save it compressed, and return the table plus a value→u16 index map.
  • generate_keyed_lookup(...) — save a key table and emit the one standard accessor shape: binary-search the keys for name, then build Struct::new(RANGES[i], RANGES[i + 1]).

Both build_caniuse_feature_matching and build_caniuse_region_matching now call them, so get_feature_stat and get_usage_by_region are byte-for-byte identical in shape.

No data change

Every .deflate blob is byte-identical (regenerated to confirm); only the generated lookup .rs style is unified. All tests and the JS-equivalence proptests pass; clippy/fmt clean.

🤖 Generated with Claude Code

The feature and region generators each hand-rolled the same two patterns: a
version-string intern table (`BTreeSet` -> sorted `Vec<String>` -> value->index
map -> save blob) and a keys-blob-plus-lookup-function emission. The latter had
drifted out of sync (one used `match`/`static RANGES`, the other
`.ok()?`/`const RANGES`).

Extract two shared helpers in `xtask` utils:
- `intern_table`: dedup+sort strings into a table, save it, return the table and
  a value->`u16` index map.
- `generate_keyed_lookup`: save a key table and emit the standard binary-search
  accessor module (`get_*` -> `Struct::new(RANGES[i], RANGES[i + 1])`).

Both generators now call them, so the generated `get_feature_stat` /
`get_usage_by_region` are identical in shape. No data change: every `.deflate`
blob is byte-identical; only the generated lookup `.rs` style is unified. All
tests and the JS-equivalence proptests pass.
@codspeed-hq

codspeed-hq Bot commented May 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing codegen-dry (7bd5e0f) with main (bde46e1)

Open in CodSpeed

@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (bde46e1) to head (7bd5e0f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #694   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files          47       47           
  Lines        2443     2443           
=======================================
  Hits         2414     2414           
  Misses         29       29           

☔ 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 dfe1e4a into main May 29, 2026
16 checks passed
@Boshen Boshen deleted the codegen-dry branch May 29, 2026 14:58
@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