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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3macOS 10.9+ x86-64

cpython_near_wasm_opt-0.8.4-py3-none-macosx_10_9_arm64.whl (7.8 MB view details)

Uploaded Python 3macOS 10.9+ ARM64

File details

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

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.4-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5df5e1cb66023ad3de352fae4f7e55efb78baea76ddf4917ac407718b4d8a035
MD5 c00c452889daf54b7faee53c9f5ace0f
BLAKE2b-256 8cd7efce6eac0379a1c00166b62095c1b21714c9b8dfd9a8f35c9c9327c90bbd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.4-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 855a4ca2504c3a03234681b5f82506943259c3f2c11a680c2d237fbb6c600a0d
MD5 2fd873facc8d343bec125f50da91cc6b
BLAKE2b-256 addeabc4745597cb90cd96385dc35976f4e090744a1eeb54cfbeb91c61b7c47e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.4-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 11ac67d7397ab4712c4117b6d3a3bd74ec9a760dd2ace1ed4ad5a3e91a4e88fa
MD5 686831fec852f3b0aae789c8458d2dab
BLAKE2b-256 5cfd6cdce4a9e1867db63a3a08a7276fee623b37e764e5a6b09f8f4af2557815

See more details on using hashes here.

Provenance

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

File details

Details for the file cpython_near_wasm_opt-0.8.4-py3-none-macosx_10_9_arm64.whl.

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.4-py3-none-macosx_10_9_arm64.whl
Algorithm Hash digest
SHA256 239f1dc46411f399adcda91914ddda9176f98c979c139eb294d7b01deb16dada
MD5 8e0a3ff6556ab2e6733dd0c688063f5d
BLAKE2b-256 b5494002e193aea443dfa93d12fa10cd37912a8bf6244f0a6ca8b342c313c220

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpython_near_wasm_opt-0.8.4-py3-none-macosx_10_9_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.

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