Skip to content

feat(cpython): xz snapshot, preload urllib.request and parsers, fix doctest - #2573

Merged
chaliy merged 1 commit into
mainfrom
claude/project-thread-io7h59
Oct 7, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/project-thread-io7h59

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • The embedded CPython snapshot ships xz-compressed (artifacts/python.wasm.xz, 4.99 MB) instead of gzip (~6.7 MB). build.rs decodes it with lzma-rs, a pure-Rust build-only dependency. Runtime is unchanged.
  • The freed room preloads urllib.request (with http.client and email), tomllib, configparser and xml.etree.ElementTree in the snapshot. Importing them now costs nothing per call.
  • doctest works again: it imported pdb, which is not shipped. A small pdb stand-in now covers it, and breakpoint() prints a notice and continues.
  • mailbox is no longer shipped.

Why

The CPython crate was 10.25 MB, 236 KB under the crates.io 10 MiB cap. That cap decided what could be preloaded, so common stdlib imports still cost 0.1-0.47 s on every call.

Before / After

Before After
bashkit-cpython-wasm .crate 10,249,728 B 8,642,486 B
import urllib.request (per call) 466 ms ~0 (call total 3.9 ms)
import configparser / tomllib / xml.etree.ElementTree 123 / 120 / 104 ms ~0
python_call/cpython/print 4.03 ms 4.14 ms
first call in a process ~20 ms 20.7 ms
doctest.testmod() ModuleNotFoundError: No module named 'pdb' TestResults(failed=0, attempted=1)

Build cost: decoding the snapshot takes ~2.5 s in a debug build script, measured with lzma-rs 0.3.

Risk

  • Low
  • Building bashkit-cpython-wasm now needs lzma-rs (plus crc and crc-catalog). These are exempted in cargo-vet; the licenses are MIT/Apache.
  • Rebuilding the guest now needs xz on the build host.

Checklist

  • Tests added or updated: doctest_works_and_breakpoint_continues; stdlib_is_bytecode_only now checks that mailbox and bdb are absent.
  • Backward compatibility considered: no API change; the artifact rename is internal to the crate.

Generated by Claude Code

…octest

The CPython snapshot ships xz-compressed (4.99 MB, was ~6.7 MB gzip),
decoded by lzma-rs in build.rs. The room goes to preloading
urllib.request (http.client, email), tomllib, configparser and
xml.etree.ElementTree, whose imports drop from 0.1-0.47 s per call to ~0.
A pdb stand-in makes doctest importable; mailbox is dropped.

Claude-Session: https://claude.ai/code/session_01Ke1iW2hQi9VXioZi1avPaW
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 5183d83 Commit Preview URL

Branch Preview URL
Oct 07 2026, 04:24 PM

@chaliy
chaliy merged commit 8c0319b into main Oct 7, 2026
46 checks passed
@chaliy
chaliy deleted the claude/project-thread-io7h59 branch October 7, 2026 16:52
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