cyscale 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. cyscale-0.1.0/LICENSE +204 -0
  2. cyscale-0.1.0/NOTICE +10 -0
  3. cyscale-0.1.0/PKG-INFO +122 -0
  4. cyscale-0.1.0/README.md +88 -0
  5. cyscale-0.1.0/benchmarks/bench.py +351 -0
  6. cyscale-0.1.0/cyscale.egg-info/PKG-INFO +122 -0
  7. cyscale-0.1.0/cyscale.egg-info/SOURCES.txt +56 -0
  8. cyscale-0.1.0/cyscale.egg-info/dependency_links.txt +1 -0
  9. cyscale-0.1.0/cyscale.egg-info/requires.txt +10 -0
  10. cyscale-0.1.0/cyscale.egg-info/top_level.txt +5 -0
  11. cyscale-0.1.0/pyproject.toml +53 -0
  12. cyscale-0.1.0/scalecodec/__init__.py +2 -0
  13. cyscale-0.1.0/scalecodec/_compact.c +12962 -0
  14. cyscale-0.1.0/scalecodec/_primitives.c +41126 -0
  15. cyscale-0.1.0/scalecodec/_scale_bytes.c +30638 -0
  16. cyscale-0.1.0/scalecodec/base.c +35439 -0
  17. cyscale-0.1.0/scalecodec/constants.py +1 -0
  18. cyscale-0.1.0/scalecodec/exceptions.py +10 -0
  19. cyscale-0.1.0/scalecodec/type_registry/__init__.py +70 -0
  20. cyscale-0.1.0/scalecodec/type_registry/acala.json +29 -0
  21. cyscale-0.1.0/scalecodec/type_registry/canvas.json +103 -0
  22. cyscale-0.1.0/scalecodec/type_registry/contracts-on-rococo.json +6 -0
  23. cyscale-0.1.0/scalecodec/type_registry/core.json +3108 -0
  24. cyscale-0.1.0/scalecodec/type_registry/crust.json +291 -0
  25. cyscale-0.1.0/scalecodec/type_registry/karura.json +915 -0
  26. cyscale-0.1.0/scalecodec/type_registry/kusama.json +451 -0
  27. cyscale-0.1.0/scalecodec/type_registry/legacy.json +11278 -0
  28. cyscale-0.1.0/scalecodec/type_registry/moonbase-alpha.json +10 -0
  29. cyscale-0.1.0/scalecodec/type_registry/moonbeam.json +10 -0
  30. cyscale-0.1.0/scalecodec/type_registry/moonriver.json +82 -0
  31. cyscale-0.1.0/scalecodec/type_registry/polkadot.json +162 -0
  32. cyscale-0.1.0/scalecodec/type_registry/polymesh-mainnet.json +2839 -0
  33. cyscale-0.1.0/scalecodec/type_registry/polymesh-testnet.json +2839 -0
  34. cyscale-0.1.0/scalecodec/type_registry/rococo.json +60 -0
  35. cyscale-0.1.0/scalecodec/type_registry/statemine.json +20 -0
  36. cyscale-0.1.0/scalecodec/type_registry/statemint.json +20 -0
  37. cyscale-0.1.0/scalecodec/type_registry/substrate-node-template.json +36 -0
  38. cyscale-0.1.0/scalecodec/type_registry/test.json +163 -0
  39. cyscale-0.1.0/scalecodec/type_registry/westend.json +137 -0
  40. cyscale-0.1.0/scalecodec/types.c +90023 -0
  41. cyscale-0.1.0/scalecodec/updater.py +27 -0
  42. cyscale-0.1.0/scalecodec/utils/__init__.py +0 -0
  43. cyscale-0.1.0/scalecodec/utils/_math.c +8549 -0
  44. cyscale-0.1.0/scalecodec/utils/math.py +25 -0
  45. cyscale-0.1.0/scalecodec/utils/ss58.py +275 -0
  46. cyscale-0.1.0/setup.cfg +4 -0
  47. cyscale-0.1.0/setup.py +38 -0
  48. cyscale-0.1.0/test/test_extrinsic_payload.py +2807 -0
  49. cyscale-0.1.0/test/test_legacy_events.py +393 -0
  50. cyscale-0.1.0/test/test_metadata.py +169 -0
  51. cyscale-0.1.0/test/test_runtime_call.py +34 -0
  52. cyscale-0.1.0/test/test_runtime_configuration.py +90 -0
  53. cyscale-0.1.0/test/test_scale_info.py +310 -0
  54. cyscale-0.1.0/test/test_scale_types.py +1059 -0
  55. cyscale-0.1.0/test/test_scalebytes.py +95 -0
  56. cyscale-0.1.0/test/test_ss58.py +274 -0
  57. cyscale-0.1.0/test/test_type_encoding.py +502 -0
  58. cyscale-0.1.0/test/test_type_registry.py +205 -0
cyscale-0.1.0/LICENSE ADDED
@@ -0,0 +1,204 @@
1
+ Copyright 2026 BD Himes
2
+ Portions copyright 2018-2021 Stichting Polkascan (Polkascan Foundation)
3
+
4
+ Apache License
5
+ Version 2.0, January 2004
6
+ http://www.apache.org/licenses/
7
+
8
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
9
+
10
+ 1. Definitions.
11
+
12
+ "License" shall mean the terms and conditions for use, reproduction,
13
+ and distribution as defined by Sections 1 through 9 of this document.
14
+
15
+ "Licensor" shall mean the copyright owner or entity authorized by
16
+ the copyright owner that is granting the License.
17
+
18
+ "Legal Entity" shall mean the union of the acting entity and all
19
+ other entities that control, are controlled by, or are under common
20
+ control with that entity. For the purposes of this definition,
21
+ "control" means (i) the power, direct or indirect, to cause the
22
+ direction or management of such entity, whether by contract or
23
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
24
+ outstanding shares, or (iii) beneficial ownership of such entity.
25
+
26
+ "You" (or "Your") shall mean an individual or Legal Entity
27
+ exercising permissions granted by this License.
28
+
29
+ "Source" form shall mean the preferred form for making modifications,
30
+ including but not limited to software source code, documentation
31
+ source, and configuration files.
32
+
33
+ "Object" form shall mean any form resulting from mechanical
34
+ transformation or translation of a Source form, including but
35
+ not limited to compiled object code, generated documentation,
36
+ and conversions to other media types.
37
+
38
+ "Work" shall mean the work of authorship, whether in Source or
39
+ Object form, made available under the License, as indicated by a
40
+ copyright notice that is included in or attached to the work
41
+ (an example is provided in the Appendix below).
42
+
43
+ "Derivative Works" shall mean any work, whether in Source or Object
44
+ form, that is based on (or derived from) the Work and for which the
45
+ editorial revisions, annotations, elaborations, or other modifications
46
+ represent, as a whole, an original work of authorship. For the purposes
47
+ of this License, Derivative Works shall not include works that remain
48
+ separable from, or merely link (or bind by name) to the interfaces of,
49
+ the Work and Derivative Works thereof.
50
+
51
+ "Contribution" shall mean any work of authorship, including
52
+ the original version of the Work and any modifications or additions
53
+ to that Work or Derivative Works thereof, that is intentionally
54
+ submitted to Licensor for inclusion in the Work by the copyright owner
55
+ or by an individual or Legal Entity authorized to submit on behalf of
56
+ the copyright owner. For the purposes of this definition, "submitted"
57
+ means any form of electronic, verbal, or written communication sent
58
+ to the Licensor or its representatives, including but not limited to
59
+ communication on electronic mailing lists, source code control systems,
60
+ and issue tracking systems that are managed by, or on behalf of, the
61
+ Licensor for the purpose of discussing and improving the Work, but
62
+ excluding communication that is conspicuously marked or otherwise
63
+ designated in writing by the copyright owner as "Not a Contribution."
64
+
65
+ "Contributor" shall mean Licensor and any individual or Legal Entity
66
+ on behalf of whom a Contribution has been received by Licensor and
67
+ subsequently incorporated within the Work.
68
+
69
+ 2. Grant of Copyright License. Subject to the terms and conditions of
70
+ this License, each Contributor hereby grants to You a perpetual,
71
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
72
+ copyright license to reproduce, prepare Derivative Works of,
73
+ publicly display, publicly perform, sublicense, and distribute the
74
+ Work and such Derivative Works in Source or Object form.
75
+
76
+ 3. Grant of Patent License. Subject to the terms and conditions of
77
+ this License, each Contributor hereby grants to You a perpetual,
78
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
79
+ (except as stated in this section) patent license to make, have made,
80
+ use, offer to sell, sell, import, and otherwise transfer the Work,
81
+ where such license applies only to those patent claims licensable
82
+ by such Contributor that are necessarily infringed by their
83
+ Contribution(s) alone or by combination of their Contribution(s)
84
+ with the Work to which such Contribution(s) was submitted. If You
85
+ institute patent litigation against any entity (including a
86
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
87
+ or a Contribution incorporated within the Work constitutes direct
88
+ or contributory patent infringement, then any patent licenses
89
+ granted to You under this License for that Work shall terminate
90
+ as of the date such litigation is filed.
91
+
92
+ 4. Redistribution. You may reproduce and distribute copies of the
93
+ Work or Derivative Works thereof in any medium, with or without
94
+ modifications, and in Source or Object form, provided that You
95
+ meet the following conditions:
96
+
97
+ (a) You must give any other recipients of the Work or
98
+ Derivative Works a copy of this License; and
99
+
100
+ (b) You must cause any modified files to carry prominent notices
101
+ stating that You changed the files; and
102
+
103
+ (c) You must retain, in the Source form of any Derivative Works
104
+ that You distribute, all copyright, patent, trademark, and
105
+ attribution notices from the Source form of the Work,
106
+ excluding those notices that do not pertain to any part of
107
+ the Derivative Works; and
108
+
109
+ (d) If the Work includes a "NOTICE" text file as part of its
110
+ distribution, then any Derivative Works that You distribute must
111
+ include a readable copy of the attribution notices contained
112
+ within such NOTICE file, excluding those notices that do not
113
+ pertain to any part of the Derivative Works, in at least one
114
+ of the following places: within a NOTICE text file distributed
115
+ as part of the Derivative Works; within the Source form or
116
+ documentation, if provided along with the Derivative Works; or,
117
+ within a display generated by the Derivative Works, if and
118
+ wherever such third-party notices normally appear. The contents
119
+ of the NOTICE file are for informational purposes only and
120
+ do not modify the License. You may add Your own attribution
121
+ notices within Derivative Works that You distribute, alongside
122
+ or as an addendum to the NOTICE text from the Work, provided
123
+ that such additional attribution notices cannot be construed
124
+ as modifying the License.
125
+
126
+ You may add Your own copyright statement to Your modifications and
127
+ may provide additional or different license terms and conditions
128
+ for use, reproduction, or distribution of Your modifications, or
129
+ for any such Derivative Works as a whole, provided Your use,
130
+ reproduction, and distribution of the Work otherwise complies with
131
+ the conditions stated in this License.
132
+
133
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
134
+ any Contribution intentionally submitted for inclusion in the Work
135
+ by You to the Licensor shall be under the terms and conditions of
136
+ this License, without any additional terms or conditions.
137
+ Notwithstanding the above, nothing herein shall supersede or modify
138
+ the terms of any separate license agreement you may have executed
139
+ with Licensor regarding such Contributions.
140
+
141
+ 6. Trademarks. This License does not grant permission to use the trade
142
+ names, trademarks, service marks, or product names of the Licensor,
143
+ except as required for reasonable and customary use in describing the
144
+ origin of the Work and reproducing the content of the NOTICE file.
145
+
146
+ 7. Disclaimer of Warranty. Unless required by applicable law or
147
+ agreed to in writing, Licensor provides the Work (and each
148
+ Contributor provides its Contributions) on an "AS IS" BASIS,
149
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
150
+ implied, including, without limitation, any warranties or conditions
151
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
152
+ PARTICULAR PURPOSE. You are solely responsible for determining the
153
+ appropriateness of using or redistributing the Work and assume any
154
+ risks associated with Your exercise of permissions under this License.
155
+
156
+ 8. Limitation of Liability. In no event and under no legal theory,
157
+ whether in tort (including negligence), contract, or otherwise,
158
+ unless required by applicable law (such as deliberate and grossly
159
+ negligent acts) or agreed to in writing, shall any Contributor be
160
+ liable to You for damages, including any direct, indirect, special,
161
+ incidental, or consequential damages of any character arising as a
162
+ result of this License or out of the use or inability to use the
163
+ Work (including but not limited to damages for loss of goodwill,
164
+ work stoppage, computer failure or malfunction, or any and all
165
+ other commercial damages or losses), even if such Contributor
166
+ has been advised of the possibility of such damages.
167
+
168
+ 9. Accepting Warranty or Additional Liability. While redistributing
169
+ the Work or Derivative Works thereof, You may choose to offer,
170
+ and charge a fee for, acceptance of support, warranty, indemnity,
171
+ or other liability obligations and/or rights consistent with this
172
+ License. However, in accepting such obligations, You may act only
173
+ on Your own behalf and on Your sole responsibility, not on behalf
174
+ of any other Contributor, and only if You agree to indemnify,
175
+ defend, and hold each Contributor harmless for any liability
176
+ incurred by, or claims asserted against, such Contributor by reason
177
+ of your accepting any such warranty or additional liability.
178
+
179
+ END OF TERMS AND CONDITIONS
180
+
181
+ APPENDIX: How to apply the Apache License to your work.
182
+
183
+ To apply the Apache License to your work, attach the following
184
+ boilerplate notice, with the fields enclosed by brackets "[]"
185
+ replaced with your own identifying information. (Don't include
186
+ the brackets!) The text should be enclosed in the appropriate
187
+ comment syntax for the file format. We also recommend that a
188
+ file or class name and description of purpose be included on the
189
+ same "printed page" as the copyright notice for easier
190
+ identification within third-party archives.
191
+
192
+ Copyright [yyyy] [name of copyright owner]
193
+
194
+ Licensed under the Apache License, Version 2.0 (the "License");
195
+ you may not use this file except in compliance with the License.
196
+ You may obtain a copy of the License at
197
+
198
+ http://www.apache.org/licenses/LICENSE-2.0
199
+
200
+ Unless required by applicable law or agreed to in writing, software
201
+ distributed under the License is distributed on an "AS IS" BASIS,
202
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
203
+ See the License for the specific language governing permissions and
204
+ limitations under the License.
cyscale-0.1.0/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ cyscale
2
+ Copyright 2025 BD Himes
3
+
4
+ This product is a derivative work of py-scale-codec:
5
+ Copyright 2018-2021 Stichting Polkascan (Polkascan Foundation)
6
+ https://github.com/polkascan/py-scale-codec
7
+
8
+ The original work is licensed under the Apache License, Version 2.0.
9
+ This derivative work is also distributed under the Apache License, Version 2.0.
10
+ See the LICENSE file for the full license text.
cyscale-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.4
2
+ Name: cyscale
3
+ Version: 0.1.0
4
+ Summary: Cython SCALE Codec Library
5
+ Author-email: BD Himes <b@latent.to>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/thewhaleking/cy-scale-codec
8
+ Project-URL: Bug Reports, https://github.com/thewhaleking/cy-scale-codec/issues
9
+ Project-URL: Source, https://github.com/thewhaleking/cy-scale-codec
10
+ Keywords: scale,codec,polkascan,polkadot,substrate,blockchain,kusama,cython,bittensor
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Cython
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ License-File: NOTICE
25
+ Requires-Dist: more-itertools
26
+ Requires-Dist: base58>=2.0.1
27
+ Requires-Dist: requests>=2.24.0
28
+ Provides-Extra: test
29
+ Requires-Dist: coverage; extra == "test"
30
+ Requires-Dist: pytest; extra == "test"
31
+ Provides-Extra: cython
32
+ Requires-Dist: Cython>=3.0; extra == "cython"
33
+ Dynamic: license-file
34
+
35
+ # cyscale
36
+
37
+ [![Latest Version](https://img.shields.io/pypi/v/cyscale.svg)](https://pypi.org/project/cyscale/)
38
+ [![Supported Python versions](https://img.shields.io/pypi/pyversions/cyscale.svg)](https://pypi.org/project/cyscale/)
39
+ [![License](https://img.shields.io/pypi/l/cyscale.svg)](https://github.com/thewhaleking/cy-scale-codec/blob/master/LICENSE)
40
+
41
+ Cython-accelerated [SCALE codec](https://docs.substrate.io/reference/scale-codec/) library for Substrate-based blockchains (Polkadot, Kusama, Bittensor, etc.).
42
+
43
+ A drop-in replacement for [py-scale-codec](https://github.com/polkascan/py-scale-codec) — same `scalecodec` module name, same public API, compiled with Cython for improved throughput.
44
+
45
+ ## Installation
46
+
47
+ ```bash
48
+ pip install cyscale
49
+ ```
50
+
51
+ ## Performance
52
+
53
+ Benchmarked on Apple M-series (Python 3.13) against py-scale-codec 1.2.12.
54
+ All timings are µs per call; speedup = py ÷ cy.
55
+
56
+ ### Primitives and small types
57
+
58
+ | Benchmark | py (µs) | cy (µs) | speedup |
59
+ |-----------------------------|---------|---------|---------|
60
+ | u8 decode | 2.18 | 1.29 | 1.68× |
61
+ | u16 decode | 2.12 | 1.40 | 1.52× |
62
+ | u32 decode | 2.10 | 1.37 | 1.53× |
63
+ | u64 decode | 2.14 | 1.39 | 1.54× |
64
+ | u128 decode | 2.11 | 1.37 | 1.53× |
65
+ | Compact\<u32\> decode | 6.94 | 4.94 | 1.40× |
66
+ | bool decode | 2.10 | 1.33 | 1.58× |
67
+ | H256 decode | 2.14 | 1.37 | 1.57× |
68
+ | AccountId decode (no SS58) | 2.65 | 1.72 | 1.54× |
69
+ | Str decode | 9.20 | 6.37 | 1.44× |
70
+ | (u32, u64, bool) decode | 16.11 | 10.69 | 1.51× |
71
+ | u32 encode | 1.65 | 0.98 | 1.68× |
72
+ | u64 encode | 1.68 | 0.98 | 1.71× |
73
+ | Compact\<u32\> encode | 6.47 | 4.53 | 1.43× |
74
+ | H256 encode | 1.77 | 1.04 | 1.70× |
75
+
76
+ ### Large payloads
77
+
78
+ | Benchmark | py (µs) | cy (µs) | speedup |
79
+ |-------------------------------------------------|------------|------------|---------|
80
+ | Vec\<u32\> decode (64 elements) | 160.57 | 105.46 | 1.52× |
81
+ | Vec\<u32\> decode (1,024 elements) | 2,329.76 | 1,574.94 | 1.48× |
82
+ | Vec\<u32\> decode (16,384 elements) | 37,470.39 | 24,791.11 | 1.51× |
83
+ | Bytes decode (1 KB) | 10.35 | 7.65 | 1.35× |
84
+ | Bytes decode (64 KB) | 46.01 | 45.50 | 1.01× |
85
+ | Bytes decode (512 KB) | 270.51 | 290.45 | 0.93× |
86
+ | Vec\<EventRecord\> decode (5 events, V10) | 215.79 | 145.50 | 1.48× |
87
+ | MetadataVersioned decode (V10, 85 KB) | 47,144.57 | 33,035.40 | 1.43× |
88
+ | MetadataVersioned decode (V13, 219 KB) | 102,974.25 | 73,624.13 | 1.40× |
89
+ | MetadataVersioned decode (V14, 300 KB) | 284,478.38 | 199,015.58 | 1.43× |
90
+ | Bittensor metadata + portable registry (254 KB) | 332,447.63 | 229,223.60 | 1.45× |
91
+
92
+ Primitives and small types see **~1.4–1.7× speedup**. Large metadata decoding
93
+ sees **~1.4–1.5× speedup** — the gain compounds across thousands of recursive
94
+ decode calls. Raw bulk byte operations (`Bytes`/`Vec<u8>`) above ~64 KB are
95
+ dominated by `memcpy` and show no meaningful difference.
96
+
97
+ To reproduce, run:
98
+
99
+ ```bash
100
+ # save a py-scale-codec baseline
101
+ python benchmarks/bench.py --save-baseline benchmarks/baseline_py.json
102
+
103
+ # compare against cy-scale-codec
104
+ PYTHONPATH=. python benchmarks/bench.py --compare benchmarks/baseline_py.json
105
+ ```
106
+
107
+ ## Examples of different types
108
+
109
+ | Type | Description | Example SCALE decoding value | SCALE encoded value |
110
+ |------|-------------|------------------------------|---------------------|
111
+ | `bool` | Boolean values are encoded using the least significant bit of a single byte. | `True` | `0x01` |
112
+ | `u16` | Basic integers are encoded using a fixed-width little-endian (LE) format. | `42` | `0x2a00` |
113
+ | `Compact` | A "compact" or general integer encoding is sufficient for encoding large integers (up to 2\*\*536) and is more efficient at encoding most values than the fixed-width version. | `1` | `0x04` |
114
+ | `Vec` | A collection of same-typed values is encoded, prefixed with a compact encoding of the number of items, followed by each item's encoding concatenated in turn. | `[4, 8, 15, 16, 23, 42]` | `0x18040008000f00100017002a00` |
115
+ | `str`, `Bytes` | Strings are Vectors of bytes (`Vec<u8>`) containing a valid UTF8 sequence. | `"Test"` | `0x1054657374` |
116
+ | `AccountId` | An [SS58 formatted](https://docs.substrate.io/reference/address-formats/) representation of an account. | `"5GDyPHLVHcQYPTWfygtPYeogQjyZy7J9fsi4brPhgEFq4pcv"` | `0xb80269ec...` |
117
+ | `Enum` | A fixed number of variants, each mutually exclusive. Encoded as the first byte identifying the index of the variant. | `{'Int': 8}` | `0x002a` |
118
+ | `Struct` | For structures, values are named but that is irrelevant for the encoding (only order matters). | `{"votes": [...], "id": 4}` | `0x04b80269...` |
119
+
120
+ ## License
121
+
122
+ Apache 2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,88 @@
1
+ # cyscale
2
+
3
+ [![Latest Version](https://img.shields.io/pypi/v/cyscale.svg)](https://pypi.org/project/cyscale/)
4
+ [![Supported Python versions](https://img.shields.io/pypi/pyversions/cyscale.svg)](https://pypi.org/project/cyscale/)
5
+ [![License](https://img.shields.io/pypi/l/cyscale.svg)](https://github.com/thewhaleking/cy-scale-codec/blob/master/LICENSE)
6
+
7
+ Cython-accelerated [SCALE codec](https://docs.substrate.io/reference/scale-codec/) library for Substrate-based blockchains (Polkadot, Kusama, Bittensor, etc.).
8
+
9
+ A drop-in replacement for [py-scale-codec](https://github.com/polkascan/py-scale-codec) — same `scalecodec` module name, same public API, compiled with Cython for improved throughput.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install cyscale
15
+ ```
16
+
17
+ ## Performance
18
+
19
+ Benchmarked on Apple M-series (Python 3.13) against py-scale-codec 1.2.12.
20
+ All timings are µs per call; speedup = py ÷ cy.
21
+
22
+ ### Primitives and small types
23
+
24
+ | Benchmark | py (µs) | cy (µs) | speedup |
25
+ |-----------------------------|---------|---------|---------|
26
+ | u8 decode | 2.18 | 1.29 | 1.68× |
27
+ | u16 decode | 2.12 | 1.40 | 1.52× |
28
+ | u32 decode | 2.10 | 1.37 | 1.53× |
29
+ | u64 decode | 2.14 | 1.39 | 1.54× |
30
+ | u128 decode | 2.11 | 1.37 | 1.53× |
31
+ | Compact\<u32\> decode | 6.94 | 4.94 | 1.40× |
32
+ | bool decode | 2.10 | 1.33 | 1.58× |
33
+ | H256 decode | 2.14 | 1.37 | 1.57× |
34
+ | AccountId decode (no SS58) | 2.65 | 1.72 | 1.54× |
35
+ | Str decode | 9.20 | 6.37 | 1.44× |
36
+ | (u32, u64, bool) decode | 16.11 | 10.69 | 1.51× |
37
+ | u32 encode | 1.65 | 0.98 | 1.68× |
38
+ | u64 encode | 1.68 | 0.98 | 1.71× |
39
+ | Compact\<u32\> encode | 6.47 | 4.53 | 1.43× |
40
+ | H256 encode | 1.77 | 1.04 | 1.70× |
41
+
42
+ ### Large payloads
43
+
44
+ | Benchmark | py (µs) | cy (µs) | speedup |
45
+ |-------------------------------------------------|------------|------------|---------|
46
+ | Vec\<u32\> decode (64 elements) | 160.57 | 105.46 | 1.52× |
47
+ | Vec\<u32\> decode (1,024 elements) | 2,329.76 | 1,574.94 | 1.48× |
48
+ | Vec\<u32\> decode (16,384 elements) | 37,470.39 | 24,791.11 | 1.51× |
49
+ | Bytes decode (1 KB) | 10.35 | 7.65 | 1.35× |
50
+ | Bytes decode (64 KB) | 46.01 | 45.50 | 1.01× |
51
+ | Bytes decode (512 KB) | 270.51 | 290.45 | 0.93× |
52
+ | Vec\<EventRecord\> decode (5 events, V10) | 215.79 | 145.50 | 1.48× |
53
+ | MetadataVersioned decode (V10, 85 KB) | 47,144.57 | 33,035.40 | 1.43× |
54
+ | MetadataVersioned decode (V13, 219 KB) | 102,974.25 | 73,624.13 | 1.40× |
55
+ | MetadataVersioned decode (V14, 300 KB) | 284,478.38 | 199,015.58 | 1.43× |
56
+ | Bittensor metadata + portable registry (254 KB) | 332,447.63 | 229,223.60 | 1.45× |
57
+
58
+ Primitives and small types see **~1.4–1.7× speedup**. Large metadata decoding
59
+ sees **~1.4–1.5× speedup** — the gain compounds across thousands of recursive
60
+ decode calls. Raw bulk byte operations (`Bytes`/`Vec<u8>`) above ~64 KB are
61
+ dominated by `memcpy` and show no meaningful difference.
62
+
63
+ To reproduce, run:
64
+
65
+ ```bash
66
+ # save a py-scale-codec baseline
67
+ python benchmarks/bench.py --save-baseline benchmarks/baseline_py.json
68
+
69
+ # compare against cy-scale-codec
70
+ PYTHONPATH=. python benchmarks/bench.py --compare benchmarks/baseline_py.json
71
+ ```
72
+
73
+ ## Examples of different types
74
+
75
+ | Type | Description | Example SCALE decoding value | SCALE encoded value |
76
+ |------|-------------|------------------------------|---------------------|
77
+ | `bool` | Boolean values are encoded using the least significant bit of a single byte. | `True` | `0x01` |
78
+ | `u16` | Basic integers are encoded using a fixed-width little-endian (LE) format. | `42` | `0x2a00` |
79
+ | `Compact` | A "compact" or general integer encoding is sufficient for encoding large integers (up to 2\*\*536) and is more efficient at encoding most values than the fixed-width version. | `1` | `0x04` |
80
+ | `Vec` | A collection of same-typed values is encoded, prefixed with a compact encoding of the number of items, followed by each item's encoding concatenated in turn. | `[4, 8, 15, 16, 23, 42]` | `0x18040008000f00100017002a00` |
81
+ | `str`, `Bytes` | Strings are Vectors of bytes (`Vec<u8>`) containing a valid UTF8 sequence. | `"Test"` | `0x1054657374` |
82
+ | `AccountId` | An [SS58 formatted](https://docs.substrate.io/reference/address-formats/) representation of an account. | `"5GDyPHLVHcQYPTWfygtPYeogQjyZy7J9fsi4brPhgEFq4pcv"` | `0xb80269ec...` |
83
+ | `Enum` | A fixed number of variants, each mutually exclusive. Encoded as the first byte identifying the index of the variant. | `{'Int': 8}` | `0x002a` |
84
+ | `Struct` | For structures, values are named but that is irrelevant for the encoding (only order matters). | `{"votes": [...], "id": 4}` | `0x04b80269...` |
85
+
86
+ ## License
87
+
88
+ Apache 2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE).