Skip to main content

CPython-NEAR WASM optimizer tool

Project description

CPython-NEAR WASM optimizer tool

Allows packaging arbitray Python modules together with the contract source files into a self-contained WASM file ready for running on the NEAR blockchain.

Inputs: python.wasm -- pre-compiled CPython-NEAR WASM python-stdlib.zip -- pre-compiled CPython-NEAR stdlib .pyc files lib/ -- directory with contract source files and arbitrary Python modules to package into the WASM file

Optimizations: Optimizer runs the supplied contract with default arguments (or ones specified via @near.optimizer_inputs() decorator) and traces which Python modules and WASM functions get loaded/called during the runtime, removing unreferenced ones according to the optimization settings specified via -Ox, --module-tracing=1/0, --function-tracing=off/safe/aggressive cmdline arguments.

--function-tracing=safe (-O2 and lower) tries to only remove WASM functions which belong to non-referenced builtin Python modules, which is safer than --function-tracing=aggressive (-O3 and higher), which removes all unreferenced WASM functions except those pinned via DEFAULT_PINNED_FUNCTIONS or --pinned-functions=,,...

Optimized out WASM functions are replaced with a panic handler, which will, in case such a function has still been called during the contract runtime, print a message including the missing function name, which then can be added to the pinned function name list to ensure it is retained.

Additionally, LZ4 compression can be applied to WASM data initializer, which allows up to 500KiB WASM size reduction while consuming ~20Tgas for decompression.

Typical WASM sizes after optimization with json module included (-O4/3/2): 530/560/1363KiB.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cpython_near_wasm_opt-0.8.5-py3-none-win_amd64.whl (13.0 MB view details)

Uploaded Python 3Windows x86-64

cpython_near_wasm_opt-0.8.5-py3-none-macosx_11_0_arm64.whl (7.8 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

cpython_near_wasm_opt-0.8.5-py3-none-macosx_10_9_x86_64.whl (9.0 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

File details

Details for the file cpython_near_wasm_opt-0.8.5-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.5-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c815be37d33c9bed256c117da28791f7a64e4e92c44f25313f986fb37ef22ddc
MD5 6c1ddd38e0be06737dc3c060092e4198
BLAKE2b-256 98ee79313af2ec4892401c994c4154b3a8fac251f10d7d7a49fc3a11844db7d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpython_near_wasm_opt-0.8.5-py3-none-win_amd64.whl:

Publisher: build.yml on past-hypothesis/cpython-near-wasm-opt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpython_near_wasm_opt-0.8.5-py3-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.5-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6fb85640163b9519067bfbdbdaed36104abeb8ad80ff865c162a27bb9a641fbf
MD5 e90607dbfc87efd9ca16c9a7026342c6
BLAKE2b-256 f9f9aa74cb1f54727ecb461482d423283f0ac024907e5e28b988ae4df78d6faf

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpython_near_wasm_opt-0.8.5-py3-none-manylinux1_x86_64.whl:

Publisher: build.yml on past-hypothesis/cpython-near-wasm-opt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpython_near_wasm_opt-0.8.5-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.5-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 295c15bc212298ca214cc88daa70f5333cd7479f757c3d0b27e18a697e8664a7
MD5 3785c8d22a844195bb929c94550aeecb
BLAKE2b-256 5573eff6207a5ad4055b89e32347e86cfc62096190eeefbe1b81587fe9a0e8ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpython_near_wasm_opt-0.8.5-py3-none-macosx_11_0_arm64.whl:

Publisher: build.yml on past-hypothesis/cpython-near-wasm-opt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpython_near_wasm_opt-0.8.5-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.5-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1aa2a452be8aec6f2a8292636766635a0a7953444202ddbe0216c1f8b005b80b
MD5 c3602e01f0a1f888af19846c0b1236fa
BLAKE2b-256 ff6f6cfb682668abb7ebc37f37f44e05b4e64930facf3946c7305c652f7257f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpython_near_wasm_opt-0.8.5-py3-none-macosx_10_9_x86_64.whl:

Publisher: build.yml on past-hypothesis/cpython-near-wasm-opt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page