Skip to content

perf(build): ship Plotly and non-English locales deflated - #599

Open
Leo310 wants to merge 2 commits into
mainfrom
perf/compress-locales-plotly
Open

Leo310 wants to merge 2 commits into
mainfrom
perf/compress-locales-plotly

Conversation

@Leo310

@Leo310 Leo310 commented Nov 26, 2026

Copy link
Copy Markdown
Member

What

Obsidian's plugin scan warned that main.js in 2.6.0 is over 5 MB, the per-file limit of Obsidian Sync Standard. This change ships the two largest blocks of rarely-read text deflated and inflates them on first use:

  • Plotly (the widget library, 1.75 MB raw) becomes a ?deflate import. Vendored-lib patches are applied before compression, and the source is inflated the first time a widget requests libs: plotly.
  • The ten non-English locales become one deflated pack per locale (virtual:s2b-locale-packs). Only the active locale is inflated, at first t(). English stays plain JSON because it is the fallback and the source of the key types. The raw catalogs were costlier than their file size: the minifier escapes every non-ASCII character as \uXXXX.

Inflation is synchronous, so t() keeps its contract, via pako, which pdf-lib already bundles. The new direct dependency pins the same major, so only one copy ships. The plugin is registered in both vite.config.ts and vitest.config.ts, so tests decode exactly what ships.

main.js: 8.58 MB → 6.96 MB (Plotly 731 KB, all locales ≈ 380 KB). This is still above 5 MB; getting under it needs more work (Plotly on demand, zod dedupe, pdf-lib).

How I tested it

  • bun run check, format, lint, and test pass. New test/bundling/compressedAssets.test.ts round-trips non-ASCII text, checks that every locale pack inflates to its catalogs, and translates from a compressed locale. widgetLibs.test.ts asserts the inflated Plotly is byte-identical to the patched source.
  • The production build passes the forbidden-pattern scan. Measured with vite build --mode production.
  • Not yet tested live: a German (or other non-English) UI and a Plotly widget in a real vault.

AI assistance: Claude Code wrote the change from the maintainer's brief to cut bundle size by compressing locales and Plotly; the maintainer still needs to review it and test it live.

Checklist

  • bun run check, bun run format, bun run lint, and bun run test pass locally
  • I tried the change in a real Obsidian vault (or explained above why that isn't applicable)
  • I read CONTRIBUTING.md, including the section on AI assistance
  • If this adds a provider, a bundled skill, a built-in tool, or changes manifest.json: I noted that the docs site needs updating (see "Documentation" in CONTRIBUTING.md) — n/a

main.js was 8.6 MB, over the 5 MB file limit of Obsidian Sync Standard that
the plugin review warns about. The two largest items were text the plugin
rarely reads in full: the Plotly build widgets inline (1.75 MB) and ten
non-English locale catalogs, which the minifier inflates further by escaping
every non-ASCII character. Both now ship raw-deflated as base64 and are
inflated synchronously with pako (already bundled via pdf-lib) on first use:
the active locale at startup, Plotly when a widget first asks for it.

main.js: 8.58 MB -> 6.96 MB.

Co-Authored-By: Claude <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; the previous dotfile build failure is fixed.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous dotfile build failure is fixed.

Summary

This PR ships Plotly and non-English translations compressed, then restores their text on first use.

  • Plotly stays compressed until a widget needs its source.
  • Non-English translations load from compressed catalogs on first use.

Reviews (2) · Last reviewed commit: "fix(build): skip non-directory entries w..." · Reviewed by Greptile

Comment thread src/bundling/compressedAssets.ts Resolved
A .DS_Store in the locales folder reached readdirSync as a directory in the
watch-file loop and failed the build with ENOTDIR. Both loops now share one
directory filter.

Co-Authored-By: Claude <noreply@anthropic.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