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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3macOS 11.0+ ARM64

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

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.7-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 cd082019082742bdf75616893342c9ef2f774048ba52687a0559290f42117572
MD5 72f8f060fbe042218c2ca87f4d7b9a0d
BLAKE2b-256 5fd6ce02e371e0a989ffde6e3406514d351a0750145aec2024864c05ea197ad6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.7-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8b73292350e7e875ffb86f4120c4a68f3476f41213bd93d4fb1734cdb29b547e
MD5 476e8ad94ed17a87323b4cf27f1d2f8a
BLAKE2b-256 03268ed5387fd26a049a77caec074e03ba5c22c8d7330fac9309bd44a86523c2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.7-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7ccf44877fb1ac576440113bb2f4a8e1f496cb4f5e47c3e1c660a49a3a685ed0
MD5 cf13769dc2e1d7502ca35626f13f700d
BLAKE2b-256 ee499e330116964347c0f2442fb2916478a6f0c4277d4f94d057a8eae5473259

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpython_near_wasm_opt-0.8.7-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 77d43c071ab401cae76aa4b7ca297206e470ab626c369d91f2e4a9229e943861
MD5 15ef116d3b0c9ca1292786f115b4c52d
BLAKE2b-256 4f0b8eb8d58e0afa36afc03542443fa2e90a7f044440c184189819270d55b4fa

See more details on using hashes here.

Provenance

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