Skip to content

Upgrade Bun to 1.4 and measure test plus backend wins #171

Closed

Description

@HMarzban

Goal

Raise the monorepo Bun floor from 1.3.7 to 1.4.0. Measure what 1.4 changes on this repo. Then keep only the test and runtime APIs that win on our machines.

Facts (2026-08-21)

  • Latest stable is Bun 1.4.0, published 20 August 2026. No 1.4.x patch yet. Release · Blog
  • Root engines.bun is >=1.3.7. README and docs/self-hosting/README.md say the same.
  • CI setup-bun defaults to latest. Docker uses oven/bun:1-slim. Those may already pull 1.4 once Oven publishes the tag.
  • bun-types is still ^1.3.13 / ^1.3.14.
  • bun test runs on hocuspocus, email-templates, floating-popover, and hyperlink units. Jest and Cypress stay on Node or the browser.
  • Official Bun 1.4 claims (quote only; not our numbers): idle CPU down 5×; memory down up to 35%; Linux start 50% faster; Bun.serve peak 45 MB → 36 MB (−20%). Source: bun.com/blog/bun-v1.4
  • --parallel, --isolate, --shard, and --changed landed in 1.3.13. 1.4 adds --timings and isolate bug fixes. Test parallel docs
  • Keep the metascraper 5.50.6 pin until bun -e "await import('metascraper')" succeeds on 1.4.0. The 1.4 post does not claim a require(esm) fix for mime@4.
  • Do not export default a Hono app. Bun still auto-serves that on :3000.
  • Do not treat 1.4 as unlocking @hocuspocus v4. The v4 Node crossws adapter still throws when "Bun" in globalThis.
  • Do not replace Prisma, BullMQ, or ioredis with Bun.SQL, Bun.cron, or Bun.redis on this ticket.

What to build

A measured upgrade. Not a rewrite.

  1. Soak 1.4.0 locally and in CI. Confirm Docker 1-slim is 1.4.
  2. Smoke: REST, WS, and worker start; import('metascraper'); Prisma engines (NODE_MODULE_VERSION 147); Redis TLS names; pad persist (document:saved).
  3. Raise engines.bun, bun-types, README, self-hosting, and AGENTS.md floors in the same change.
  4. On the bun test suites only: try --isolate, then --parallel, then --timings plus --shard if CI time drops.
  5. Profile hocuspocus with --cpu-prof-md / --heap-prof-md only if RSS or idle CPU improves versus 1.3.14. Consider process.on("memoryPressure") only after that profile.
  6. Re-check idleTimeout default and the ws maxPayload ignore. Keep explicit idleTimeout: 60 unless 1.4 changes the hazard.

Out of scope

  • Moving Jest or Cypress onto bun test.
  • Experimental HTTP/3 on Bun.serve.
  • Isolated linker or lockfileVersion: 2 unless bun install forces it. Existing bun.lock stays hoisted.
  • @hocuspocus v4.

Acceptance criteria

  • Local bun --version is 1.4.0 or newer. make dest-local starts REST on :4000 with no second listener on :3000.
  • cd apps/hocuspocus.server && bun -e "await import('metascraper')" is recorded. Keep or drop the 5.50.6 overrides from that result, not from the blog.
  • Prisma and Redis still work. Note any ERR_TLS_CERT_ALTNAME_INVALID and the fix (servername).
  • Root engines.bun, catalog bun-types, README, docs/self-hosting/README.md, and AGENTS.md name the new floor.
  • hocuspocus bun test is green on 1.4. The PR records whether --parallel, --isolate, or --timings stayed.
  • One before/after note for REST idle RSS or a bun test wall-clock. Official Bun numbers are not a substitute.

Blocked by

None. Can wait for the product v2.0.0 tag if the maintainer wants that first. Does not depend on the Next 16 ticket.

Activity

  1. added
    enhancement
    on Aug 21, 2026
  2. HMarzban commented on Aug 31, 2026

    @HMarzban
    CollaboratorAuthor

    Shipped in v2.0.1. Verified on the production host in deploy 33367037524.

    Acceptance criteria

    • Local Bun is 1.4.0+, REST on :4000 with no second listener on :3000. Confirmed. A default-exported Hono app is still auto-served on :3000 in 1.4.0, so that invariant stays.
    • await import('metascraper') recorded; keep or drop the overrides from that result. KEEP the pin. See below — this is the most useful thing the ticket produced.
    • Prisma still works. It generates and loads its engine on 1.4.0. process.versions.modules moves 137 → 147, but the N-API ABI is unchanged so Prisma is unaffected.
    • Redis TLS — not applicable rather than passing. No ERR_TLS_CERT_ALTNAME_INVALID appeared because the TLS branch is off in every environment template. It was never exercised.
    • Floors named in engines.bun, both bun-types entries, README.md, docs/self-hosting/README.md, apps/hocuspocus.server/Readme.md, extensions/README.md and AGENTS.md.
    • hocuspocus bun test green, and which flags stayed. 578 pass / 0 fail. No bun test flag stayed.
    • A before/after note. Several, below.

    Which test flags stayed: none

    flag result
    --parallel 7.2s → 6.0s, but Bun 1.3.14 also reaches 6.0s. Not a 1.4 win. Coverage falls 75.41% → 71.46% and drifts between runs, which disqualifies it as a gate.
    --isolate 8% slower on hocuspocus, 24% slower on the hyperlink units. No change in results.
    --timings / --update-timings Nothing outside noise.
    --parallel-delay=0 Genuine finding: it erases the small-suite penalty (48ms → 30ms). Still not adopted.

    The suite got 61% faster anyway — from removing four Bun.sleep calls, not from the runtime. Measured 2×2: on the unchanged tests Bun 1.3.14 took 7,256ms and Bun 1.4.0 took 7,952ms, so 1.4.0 was slightly slower. The runtime deserves no credit here.

    The real parallelism win was bun run --parallel on the five clean-room suites — a different feature from bun test --parallel. 209s → 88s locally.

    The metascraper pin stays, and that answer cost a deploy

    We dropped it at ^5.56.2. Deploy 33365858244 then failed Backend E2E on Bun 1.4.0, Linux x64, with the exact error the pin exists to prevent:

    @metascraper/helpers/src/index.js:6
    const mime = require('mime').default
    TypeError: require() async module ".../node_modules/.bun/mime@4..."
    

    Four local checks passed before it shipped, and all four were wrong: await import('metascraper'), a createRequire call on the helpers CJS entry, a real REST start that served /api/metadata with a scraped title, and 578 backend tests. This laptop still cannot reproduce the fault even after reverting.

    bun -e evaluates in an ESM context where Bun can await the module graph. The fault needs a CJS module on disk doing a synchronous bare require() at module scope. Only the Backend E2E job on a (build): commit can settle it, and bun run check:ci skips that job. All of this is now in AGENTS.md §Dependencies.

    Measured

    Production host, deploy 33367037524:

    before after
    Production Docker build 997s 683s
    webapp image 727 MB 332 MB
    backend image 5.67 GB 961 MB
    Backend test suite 7.9s 3.1s
    Extension test gate 209s 88s
    Full local check:ci 290s 163s
    Idle RSS, trivial Bun.serve 32,096 KiB 17,648 KiB

    [email protected] also changed complexity class: a 954 KiB document went from 120,100ms on 1.3.14 to 76ms on 1.4.0. MAX_MARKDOWN_CHARS stays at 64 KiB anyway — that fixture was ordinary prose, and the cap defends against hostile input, which nobody re-tested.

    Not proven

    • The vendor claims in this ticket's Facts block stay vendor claims. Idle CPU down 5×, memory down up to 35%, Linux start 50% faster — none reproduced here, and the one release-note claim tested on our hardware (faster zlib decompression) did not reproduce.
    • The pad persist round trip (document:saved) was never driven end to end.
    • Redis TLS, as above.

    Closing. Follow-up work is tracked separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DevOpsenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions