From 9566f305b50578e47b533e7f24379860387ee8af Mon Sep 17 00:00:00 2001 From: setop Date: Sat, 27 Sep 2025 18:10:33 +0200 Subject: [PATCH] more exploration --- README.md | 6 +++++- TODO.md | 8 ++++++++ build.sh | 4 +++- dom.js | 4 ---- launch.js => postelm.js | 0 preelm.js | 6 ++++++ 6 files changed, 22 insertions(+), 6 deletions(-) rename launch.js => postelm.js (100%) create mode 100644 preelm.js diff --git a/README.md b/README.md index 57f661d..3bd2ea6 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,14 @@ A tool to generate HTML code from Elm source in the terminal using [QuickJS](htt * do not patch elm compiler output * provide acceptable performances (500ms for a big script) + # Design QuickJS (Qjs) is a [JavaScript runtime](https://en.wikipedia.org/wiki/List_of_JavaScript_engines), similar to V8 or SpiderMonkey, but lighter and faster. As any runtime, Qjs can interpret JavaScript code, but it is not a web browser. It has no concept of an HTML document. -To bridge this gap, we add a minimal [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model) implementation. +To bridge this gap, we add a minimal [DOM](https://dom.spec.whatwg.org/) implementation. Next, we concatenate this with the Elm JavaScript output and an app launcher snippet, then ask Qjs to interpret all of it. @@ -24,6 +25,8 @@ Next, we concatenate this with the Elm JavaScript output and an app launcher sni * Hence, no [TEA](https://guide.elm-lang.org/architecture/); the `main` function must return a static view * Hence, no Time, no Random, no Json Encoder/Decoder (!), no Http * Nodes can only have one parent (this should always be the case) +* Does not scale well : creating thousands of Nodes consumes a [lot of RAM](#Performances) + # Usage @@ -51,6 +54,7 @@ Hello World! Acceptable for small scripts : 250ms on a modest x86_64 CPU and 64MB RAM for a 500 records into a table ; but is does not scale well as everything is loaded before processing ; no streaming contrary to the usual Unix way. +Generate 500k "li" loop took 17s and 900MB RAM. # Prior Work diff --git a/TODO.md b/TODO.md index 145d287..b804b83 100644 --- a/TODO.md +++ b/TODO.md @@ -6,8 +6,16 @@ - [ ] from files (use case : SSG) - [ ] from http (use case : spider) +- implements some missing Web API: + - [Events](https://dom.spec.whatwg.org/#events) + - [Fetch](https://fetch.spec.whatwg.org/)(or [XMLHttpRequest](https://xhr.spec.whatwg.org/)) + - [Promise](https://webidl.spec.whatwg.org/#a-new-promise) (if needed by the above) + - [ ] find a way to create a standalone executable (maybe with a combination of Google Closure Compiler and qjsc) +- [ ] find a way to stream instead of having the whole document in memory (output as soon as a node is created ? a child is added ?) + + # Minor - [ ] support for Elm debug mode (qjs does not implement `console.warn`, only `console.log`) diff --git a/build.sh b/build.sh index 7c67b11..9af20a9 100755 --- a/build.sh +++ b/build.sh @@ -1,12 +1,14 @@ #!/bin/sh -eu +CMDD=$(dirname $(realpath 0)) + w1="$(mktemp out_$$_1_XXXX.js)" elm make --optimize --output=${w1} $1 1>&2 w2="$(mktemp out_$$_XXXX.js)" -cat dom.js ${w1} launch.js > ${w2} +cat ${CMDD}/dom.js ${CMDD}/preelm.js ${w1} ${CMDD}/postelm.js > ${w2} rm ${w1} diff --git a/dom.js b/dom.js index 7caac64..8122322 100644 --- a/dom.js +++ b/dom.js @@ -52,7 +52,3 @@ document.getElementById = (_id) => { return target} document.createElement = (tag) => new Node(null, tag); document.createTextNode = (text) => { t = new Node(null, "#text" ); t.text = text; return t } - -try { - -// here will come the Elm app code diff --git a/launch.js b/postelm.js similarity index 100% rename from launch.js rename to postelm.js diff --git a/preelm.js b/preelm.js new file mode 100644 index 0000000..6d86e51 --- /dev/null +++ b/preelm.js @@ -0,0 +1,6 @@ + +try { + +// here will come the Elm app code + +