You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sha256tree.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Information on the new (sha256tree) operator
2
2
3
-
Adding `sha256tree` as a native operator made sense as it is one of the most common functions, used in nearly every shipped ChiaLisp puzzle.
3
+
Adding `sha256tree` as a native operator made sense as it is one of the most common functions, used in nearly every shipped ChiaLisp puzzle.
4
4
Furthermore it has an innate inefficiency in it's in-language implementation.
5
5
Every internal hash is allocated as an atom in clvm_rs allocator.
6
6
In addition to this, a native operator also opens the door to future optimisations via caching.
@@ -9,8 +9,9 @@ In addition to this, a native operator also opens the door to future optimisatio
9
9
10
10
The matter of how to assign Cost to the new operator was the subject of intense thought and debate.
11
11
It should be costed in proportion to:
12
+
12
13
- the time to Cost vs other operators, and especially the `sha256` operator
13
-
- the time to Cost ratio of the ChiaLisp implementation
14
+
- the time to Cost ratio of the ChiaLisp implementation
14
15
- the size of its inputs
15
16
16
17
The lattermost being a unique problem with regards to shatree as it is the first operator that parses trees, so utmost care must be taken when assigning cost.
@@ -21,7 +22,7 @@ One final consideration while costing is that we required it to tally the cost d
21
22
22
23
The `BASE_COST` was set to equal the base cost of `sha256`.
23
24
24
-
The `COST_PER_BYTES32` was designed as the sha256 operation operates on 32byte chunks. We set the Cost to be on parity with the Cost of `sha256` although sha256 costs `per byte` and `per arg`.
25
+
The `COST_PER_BYTES32` was designed as the sha256 operation operates on 32byte chunks. We set the Cost to be on parity with the Cost of `sha256` although sha256 costs `per byte` and `per arg`.
25
26
We can ignore `per arg` as `sha256tree` only takes a single argument, and we benchmarked the `cost-per-bytes32` so that it matches `sha256`'s `cost-per-byte`.
26
27
27
28
The calculations for this can be seen in the file `benchmark-clvm-cost.rs`.
@@ -34,24 +35,25 @@ The calculations for this can be seen in the file `sha256tree-benching.rs`.
34
35
## Costing Results
35
36
36
37
`MacOS M1`
38
+
37
39
```
38
-
Costs based on an increasing atom per bytes32 chunks:
40
+
Costs based on an increasing atom per bytes32 chunks:
39
41
Native time per bytes32 (ns): 95.1425
40
42
CLVM time per bytes32 (ns): 94.9895
41
43
Native implementation takes 100.1611% of the time.
42
44
Native cost per bytes32 : 64.0000
43
45
CLVM cost per bytes32 : 64.0000
44
46
100.1611% of the CLVM cost is: : 64.1031
45
47
46
-
Costs based on growing a balanced binary tree:
48
+
Costs based on growing a balanced binary tree:
47
49
Native time per node (ns): 203.8718
48
50
CLVM time per node (ns): 517.8038
49
51
Native implementation takes 39.3724% of the time.
50
52
Native cost per node : 564.0000
51
53
CLVM cost per node : 1463.0000
52
54
39.3724% of the CLVM cost is: : 576.0185
53
55
54
-
Costs based on growing a list:
56
+
Costs based on growing a list:
55
57
Native time per node (ns): 115.0891
56
58
CLVM time per node (ns): 397.1927
57
59
Native implementation takes 28.9756% of the time.
@@ -61,6 +63,7 @@ CLVM cost per node : 1399.0000
61
63
```
62
64
63
65
`Windows`
66
+
64
67
```
65
68
Costs based on an increasing atom per bytes32 chunks:
66
69
Native time per bytes32 (ns): 10.4049
@@ -87,7 +90,6 @@ CLVM cost per node : 1399.0000
87
90
10.0416% of the CLVM cost is: : 140.4821
88
91
```
89
92
90
-
91
93
## Costing Graphs
92
94
93
95
Below are the generated benchmarking graphs (PNG) from running `sha256tree-benching.rs` on Macbook M1.
@@ -103,5 +105,3 @@ Below are the generated benchmarking graphs (PNG) from running `sha256tree-bench
0 commit comments