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.2-py3-none-win_amd64.whl (13.0 MB view details)

Uploaded Python 3Windows x86-64

cpython_near_wasm_opt-0.8.2-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.2-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 0d1d4886699d58215ff35b58e1bd21bea3b71b7306d4beb231a27ebfd2a12dbb
MD5 9f882ea4bb3f343e2d8b183b21822b7b
BLAKE2b-256 99638b746220db4e4e12629ea02e311b2fc66f9c5b47b113df9eb356de5664a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpython_near_wasm_opt-0.8.2-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.2-py3-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.2-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 db212236328cfe7b499789aed53b63c1d513401584dcf32d3123b41d413b4e5e
MD5 0f4cea03ef51ed7c6306fe23de0ab301
BLAKE2b-256 60396c81dea8be78e3c7ca391959e56ab14b87cc805c45b22787436976af7a91

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpython_near_wasm_opt-0.8.2-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.2-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.2-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6483003c527b7dec9fdd7c94c02c22d8efef59a3c7ce956ddc487b0c7c3b5f09
MD5 afb2e8bdb0607a40ed7f4d76967de19e
BLAKE2b-256 3a5a29769b0659c107c1f67e2df2f1b9e97fd9e402d780cc4511864a2ad67fee

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpython_near_wasm_opt-0.8.2-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