-
Notifications
You must be signed in to change notification settings - Fork 2
/
notes.txt
57 lines (39 loc) · 1.75 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Mappings can only be state variables, not memory. This means we can't
use a map to remember pushed rules. Fortunately, we can know all rules
in advance and use an in-memory struct to keep a stack for each of them
(Tracery doesn't permit dynamic creation of rule names.)
-----
Strings don't have a way to append, or insert other than low-level memcpy's.
Seem better to use a bytes array to build up a string, and only return a
string at the last minute. memcpy() from the solidity-stringutils package
is written partially in assembly.
-----
I tested three ways of picking strings, in testchoice.sol. I then measured
their code size (if compiled one by one in a sample transaction) and their
gas usage in Remix online.
1) Nested if with a literal in each clause.
code size: 4460
gas cost (excluding transaction): 22710, 22548, 22602
2) Static array literal of strings
code size: 4198
gas cost: 24682, 24682, 24682
3) Nested if referencing portions of a packed string
code size: 3676
gas cost: 22798, 22879, 22744
The packed string seems a clear winner.
-----
animals.sol compiled with per-function packing: 12352 bytes
animals.sol compiles with global packing: 12264
-----
TODOs:
* Unicode characters aren't handled correctly, figure out where I need to
do .encode( "utf-8" ) before output
* Warn about contract length if too long
* Come up with a clever string-packing algorithm to save a little more space
* "Longest common supersequence"?
* Look for ways to make the contract more efficient.
* Idea: eliminate the loop when copying a literal less than 32 bytes long?
* Allow deletion of content.
* I was thinking of making this a paid operation.
* Would running a tracery virtual machine inside Solidity be more
space-efficient? Perhaps at higher gas cost.