pine-vm / pine

Cross-platform runtime environment for the Elm programming language.
https://pine-vm.org
MIT License
217 stars 17 forks source link

Suggestion: using elm-serialize #20

Open MattiaVerticchio opened 1 year ago

MattiaVerticchio commented 1 year ago

I want to make a suggestion, hoping it’s useful. 😁

I’ve read this response about the maximum supported model size of 166,6 MB (JSON encoded).

The package elm-serialize produces compressed JSON encoding.

There is a post on the Elm Discourse and it proved to be beneficial in elm-review too:

elm-serialize produces a significantly compressed JSON output (or binary, but which proved to be less efficient at this time). Instead of {"expression": {"type": "Operator", "operator" : "+" } } it will be something like [0,[0,0,1,"+"]].

Overall, this reduces the total cache size from 40MB to 14MB in the large project I mentioned, and because there is less data to read from (and to write to) the slow file system, the total run time was reduced by about 15%!

Viir commented 1 year ago

Thank you for sharing this idea. It looks like it would help to avoid that limit. As far as I see, that package uses a different interface than the JSON libraries. So would it require changing the compiler to emit different code? An example of the Elm code produced by the current compiler is at https://github.com/elm-fullstack/elm-fullstack/commit/4834294bd0ef79bd01d662df33b20bcad6c221e4#diff-f9ef3d37f5a52da0a2284ac48d4a91611741f93cb0269823ee2e8cbdb8916fcf

Mid-term, it looks like said limit would be lifted by a change in the upstream project (linked issue) or the switch of Elm Fullstack to the PineVM. PineVM has its own persistence infrastructure model anyway.

peteygao commented 10 months ago

Is this issue resolved in the short term via this commit and release 2023-11-15?

Viir commented 10 months ago

Is this issue resolved in the short term via this commit and release 2023-11-15?

I now ran a test with version 2023-11-15 to find out. I tested with database sizes up to 250 MB, and that worked. So that limit of 166,6 MB is resolved.

However, at the moment, the backend still relies on compiling Elm to JavaScript and running that in a JS engine. And JS engines introduce various bottlenecks. With version 2023-11-15, you will eventually run into limits related to the JavaScript approach with larger database sizes.

We made good progress this year with the new compiler and runtime for Elm/Pine and declarative programming languages in general. Looks like we are on track to free Elm backends from JavaScript and JS engines next year.