Skip to content

feat(cpython): opt-in native code (cpython-native) - #2544

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

New opt-in feature cpython-native (bashkit and bashkit-cli; companion crate feature native). With it, build.rs compiles the CPython snapshot to machine code for Cargo's TARGET (baseline ISA, so the binary runs on any CPU of that architecture) instead of Pulley bytecode. Default cpython is unchanged.

Why

Pulley interprets every guest instruction. Native code makes calls 4-10x faster for users who can allow executable memory. Nothing is compiled at run time with either option.

Before

Pulley only: print(1) ~3.7 ms, import http.client 461 ms, fib(20) 69 ms per call. CPython test suite 17 s.

After

With cpython-native: print(1) ~0.95 ms, import http.client 34 ms, fib(20) 6.4 ms. First load in a process ~47 ms (native code cannot run from the read-only static, so the module is copied); CPython::warm_up() moves it to startup. CPython test suite 112/112 pass in 3 s. CI runs the CPython suites on the native build too.

Risk

Medium, opt-in only. Native mode runs Cranelift-generated machine code, so a code-generation bug could break the wasm sandbox (TM-PY-CPY-011). Memory config is identical to Pulley (1 GiB reservation, 64 KiB guard, explicit bounds checks). Default builds run no generated machine code.

Checklist

  • cargo test -p bashkit --features cpython-native --lib --test integration -- cpython
  • cargo clippy -p bashkit-cpython-wasm --features native --all-targets -- -D warnings, cargo clippy -p bashkit --features cpython-native
  • cargo fmt --check
  • Docs (cpython.md, docs/cli.md), knowledge (cpython-wasm.md, threat model, log)

Generated by Claude Code

Compile the CPython snapshot to native code for the build target instead
of Pulley when the cpython-native feature is on.

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 fbb14d4 Commit Preview URL

Branch Preview URL
Oct 07 2026, 05:40 AM

@chaliy
chaliy merged commit bef6085 into main Oct 7, 2026
36 checks passed
@chaliy
chaliy deleted the claude/project-thread-io7h59 branch October 7, 2026 06:04
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