Repository navigation
Shrink the bundle: split modules and pack the datasets, no behaviour change - #616
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Tree-shaking report✅ No size regression. 13 grew, 33 shrank out of 198 exports.
What changed (46)
Show the other 26
All exports (198)
How this is measuredEvery export is imported alone into an esbuild consumer bundle (minified, tree-shaken) built from the head and from the base of this pull request; the sizes are the resulting bundles, gzip is their gzipped size. 🔴 marks a regression: a pre-existing export that grew more than 20% and more than 256 B, or the bundle importing every pre-existing export growing more than 5%. 🟡 is growth under the threshold, 🟢 a decrease, ⚪ no change, 🆕 an export that does not exist on the base (never a regression), 🗑️ an export that was removed. An intentional increase is accepted with the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## claude/final-validation #616 +/- ##
=========================================================
Coverage 100.00% 100.00%
=========================================================
Files 247 255 +8
Lines 2500 2558 +58
Branches 733 745 +12
=========================================================
+ Hits 2500 2558 +58
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f41c812 to
73f824d
Compare
73f824d to
eff7dec
Compare
eff7dec to
020f6ef
Compare
020f6ef to
a40688c
Compare
…kup bundles what it reads The IBGE table went from one array of [name, code] tuples to two modules: the names joined by a separator, and the codes as base 36 differences with the check digit left out (nine codes that break the rule are kept explicitly). getAreaCodeByMunicipalityCode no longer bundles the names, and the others bundle about 40% less.
…rt of neighbouring texts The CID-10, CBO, CEST, CFOP, CNAE, NBS and service list descriptions were arrays of quoted strings. Each is now a single string with one text per line, each line starting with the number of characters it shares with the previous text, unpacked on the first read. The texts are unchanged.
…tions are packed Each state's names are one packed string that shares the start of neighbouring names, unpacked on the first read.
…gory masks CID10_SUBCATEGORIES was a record of about 2,000 categories with their subcategory digits. It is now a string of three characters per category, unpacked on the first read, which cuts what isValidCid10 bundles from 26 KB to 6 KB.
… separator before the length
…ith the bank account validator The compensation codes move to their own module, which isValidBankAccount and the bank getters both read; the ISPBs and the names are two strings unpacked on the first read.
… CST table module The subpath builds of isValidCstIbsCbs, getCstIbsCbs and isValidClassTrib shared one chunk with the 48 KB of cClassTrib descriptions; they now import only the modules they read.
…ach other's types isValidMobilePhone imported PhoneVersion from isValidPhone, which imports it back, so the subpath build merged both into one chunk with the service phone table. PhoneVersion now lives with isValidMobilePhone and isValidPhone re-exports it.
…t holds the descriptions isValidLegalNature shared one chunk with the descriptions and the legacy map of getLegalNature; the codes are now a module of their own.
…code of its state getMunicipalityByCode and getAreaCodeByMunicipalityCode read the state off the first two digits of the code.
The module kept a top-level new Map(), which the conventions forbid for module scope state and which readCodeTable already avoids. The cache is now created lazily on the first read.
The figures were measured before the datasets were packed. They now come from node scripts/tree-shaking.ts on the built branch: the size table of the getting started page, the isValidCpf intro figure, the getCities, isValidCid10 and getCid10 sizes of the utilities reference, the state and city guides and their snippets. getStates is 2.2 KB, not 2.5 KB.
Stryker's 100% threshold failed on three mutants of the code this branch adds. The write
to the cache of readCodeTable and the extra pass of calculateMunicipalityCheckDigit (it
adds Number(""), which is 0) are equivalent and carry a disable directive with the
reason. A new test pins that unpackTexts reads the first text whole, whatever start
length it claims, which kills the third.
No behavior changes.
readCodeTable and unpackTexts hid the killable variants of their cache hit condition behind a directive, and carried a stale one on a `??= new Map()` statement with no mutant. Both now read the cache as `get(key) ?? store(...)`, so no condition is left to hide. readCodeTable gets a test of its own (a table read, two tables kept apart, the same table handed back), which kills the mutant of the store call, and unpackTexts already had that test. Stryker scores 100% on both files with no directive. No behavior changes.
The table readers of getCest and the municipality DDD lookups changed after the figures were generated, so their size rows are measured again with node scripts/tree-shaking.ts on this branch.
a40688c to
e883225
Compare
Second PR of the stack (base: #615). The smallest consumer bundle without any behaviour, type or API change: only module splits, import changes and more compact, content-identical dataset encodings decoded lazily on first read.
Totals (esbuild, every export imported)
Biggest single-import wins (bytes / gzip)
getAreaCodeByMunicipalityCodeisValidCid10getCitiesgetMunicipalities,getMunicipalityByCode,getCodeByMunicipalityNamegetMunicipalitiesByAreaCodegetBanks,getBankByCode,getBankByIspb)formatIsbn,getIsbnInfogetCid10Subpath entries:
get-cst-ibs-cbs,is-valid-cst-ibs-cbsandis-valid-class-tribdrop from ~50 KB to 1-3 KB each (they shared a chunk with 48 KB of cClassTrib descriptions),is-valid-legal-naturefrom 5.9 KB to 1 KB,is-valid-mobile-phonefrom 3.8 KB to 1.9 KB (a type-only import cycle made rolldown merge the phone chunks).What changed
_internals/unpack-texts.isValidBankAccount; the cClassTrib and legal nature codes out of the modules that hold their descriptions.scripts/emits the new encodings: regenerating from the committed data reproduces every file byte for byte, and old and new tables were compared entry by entry.Trade-off
The first call of a lookup unpacks its table once (for example
isValidCid10~2.6 ms,getCid10~2 ms on a laptop); warm calls are as fast or faster (getMunicipalityByCode10.3 µs to 0.9 µs), and the next PR makes the lookups much faster still.The size figures in
docs/getting-started.md,docs/utilities.md, the README and the state-city guide (EN and PT) are regenerated fromscripts/tree-shaking.ts.Gates
vp check, tests with 100% coverage, build, jscpd, knip,check:api(731 type assertions against 2.4.0 hold), commitlint, Stryker 100% on the changed files; a differential run over 12.9M calls finds 0 output differences against #615.