swarm-game / swarm

Resource gathering + programming game
Other
837 stars 52 forks source link

Minimize generated JSON size #1907

Open byorgey opened 4 months ago

byorgey commented 4 months ago

As an experiment towards #50 (see also #347), I started up a creative scenario, loaded some code from a .sw file, ran a base program, and then serialized a snapshot of the base's CESK machine to a file. Unfortunately it was almost 3MB in size! However, most of it was unnecessary junk such as empty comments records. If we want saving games to be practical we will need to work a lot harder to minimize the size of generated JSON.

As one simple example, if a Comments record is empty we should be able to omit it entirely from the output. I'm sure there is lots more similar low-hanging fruit.

byorgey commented 4 months ago

I suspect there is a lot of bloat from multiple closures containing Envs that contain duplicate bindings. In memory, there is a lot of sharing going on, but we lose the sharing when we serialize.

byorgey commented 4 months ago

Another bit of low-hanging fruit is to make custom instances for Type and Term/Syntax where ToJSON pretty-prints to a string and FromJSON runs the parser.

xsebek commented 4 months ago

@byorgey, how about splitting low-hanging fruits from this one? 🙂

byorgey commented 4 months ago

@byorgey, how about splitting low-hanging fruits from this one? 🙂

Well, to be honest, I'm not sure what they are. I already addressed the one example I mentioned.