🚧 WIP Step 1, scaffold cljs benchmark runner

This commit is contained in:
Miguel de Benito Delgado 2026-09-20 15:11:06 +02:00
parent 723267cfdd
commit ee614ea309
6 changed files with 147 additions and 2 deletions

View File

@ -36,7 +36,7 @@
"^(?:backend|frontend|exporter|common)/deps.edn"
"^(?:backend|frontend|exporter|common)/scripts/"
"^(?:backend|frontend|exporter|common)/dev/"
"^(?:backend|frontend|exporter|common)/test/"]
"^(?:backend|frontend|exporter|common)/test/(?!benches/)"]
:linter-name true}

View File

@ -67,4 +67,8 @@
"-Dpenpot.wasm.profile-marks=true"
"-XX:+UnlockExperimentalVMOptions"
"-XX:CompileCommand=blackhole,criterium.blackhole.Blackhole::consume"]}
:renderer-bench
{:main-opts ["-m" "shadow.cljs.devtools.cli"]
:jvm-opts ["-Dpenpot.wasm.profile-marks=false"]}
}}

View File

@ -20,6 +20,7 @@
"build:storybook:assets": "node ./scripts/build-storybook-assets.js",
"build:storybook:cljs": "clojure -M:dev:shadow-cljs compile storybook",
"build:wasm": "../render-wasm/build frontend",
"build:renderer-benchmarks:runner": "clojure -M:dev:renderer-bench release bench-render-wasm-runner",
"build:app:libs": "node ./scripts/build-libs.js",
"build:app:main": "clojure -M:dev:shadow-cljs release main worker",
"build:app:worker": "clojure -M:dev:shadow-cljs release worker",
@ -30,8 +31,9 @@
"fmt:clj": "cljfmt fix --parallel=true src/ test/",
"fmt:js": "prettier -c src/**/*.stories.jsx -c playwright/**/*.js -c scripts/**/*.js -c text-editor/**/*.js -w",
"fmt:scss": "prettier -c resources/styles -c src/**/*.scss -w",
"lint:clj": "clj-kondo --fail-level error --config-dir ../.clj-kondo --lint ../common/src src/",
"lint:clj": "clj-kondo --fail-level error --config-dir ../.clj-kondo --lint ../common/src src/ test/benches/",
"lint:js": "exit 0",
"lint:renderer-benchmarks": "clj-kondo --config-dir ../.clj-kondo --lint test/benches/",
"lint:scss": "pnpm exec stylelint '{src,resources}/**/*.scss'",
"build:test": "pnpm run build:wasm && clojure -M:dev:shadow-cljs compile test",
"test": "pnpm run build:test && node target/tests/test.js",

View File

@ -166,6 +166,44 @@
:output-dir "target/bench/"
:main bench/main
:compiler-options
{:output-feature-set :es2020
:output-wrapper false
:warnings {:fn-deprecated false}}
:release
{:compiler-options
{:fn-invoke-direct true
:elide-asserts true
:anon-fn-naming-policy :off}}}
:bench-render-wasm-runner
{:target :node-script
:output-to "target/renderer-benchmarks/runner.cjs"
:output-dir "target/renderer-benchmarks/runner/"
:main benches.render-wasm.runner/-main
:devtools {:autoload false}
:compiler-options
{:output-feature-set :es2020
:output-wrapper false
:warnings {:fn-deprecated false}}
:release
{:compiler-options
{:fn-invoke-direct true
:elide-asserts true
:anon-fn-naming-policy :off}}}
:bench-render-wasm-browser
{:target :esm
:output-dir "target/renderer-benchmarks/browser/"
:js-options {:js-provider :import}
:modules
{:browser
{:exports {default benches.render-wasm.browser/bridge}}}
:compiler-options
{:output-feature-set :es2020
:output-wrapper false

View File

@ -0,0 +1,33 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns benches.render-wasm.browser
"Browser entry for the CLJS renderer benchmark suite.
Requiring `app.render-wasm.api.enums` binds the enum table from the
prepared renderer build's `shared.js` at namespace load time. A missing
`shared.js` fails the compile; a stale or mismatched one throws at load.
The exported `bridge` is the only handle the Node runner uses inside the
page. Keep the boundary plain data: never pass a compiled CLJS closure
through `page.evaluate`."
(:require
[app.render-wasm.api.enums]))
(defn ping
"Bridge placeholder that checks the Node/browser boundary.
TODO(mem:render-wasm/performance/cljs-rewrite/05-browser-load-pilot):
replace with the renderer load and measurement protocol."
[]
#js {"status" "ok"})
(def bridge
"Browser-side bridge exported from the compiled module.
TODO(mem:render-wasm/performance/cljs-rewrite/06-render-and-interaction-protocol):
add `runAttempt`, `dispose` and the render completion protocol."
#js {"ping" ping})

View File

@ -0,0 +1,68 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns benches.render-wasm.runner
"Node CLI entry for the CLJS renderer benchmark suite.
Scaffolding only. Commands, options, result reporting and failure
accounting are owned by the tickets referenced below."
(:require
[clojure.string :as str]
[clojure.tools.cli :refer [parse-opts]]))
(enable-console-print!)
(def cli-options
[["-h" "--help" "Print this help"]])
(defn- argv
[]
(let [args (->> (.-argv js/process)
(array-seq)
(drop 2))]
;; `pnpm run <script> -- ...` forwards the separator, so drop one
;; leading `--` before handing the args to tools.cli.
(cond-> args
(= "--" (first args)) rest)))
(defn- usage
[summary]
(str "Usage: node target/renderer-benchmarks/runner.cjs [options]\n\n"
"Options:\n"
summary "\n\n"
"No command is implemented yet. Upcoming tickets add:\n"
" run benchmark standard fixtures and operations\n"
" ab feature A/B matrix\n"
" compare offline comparison of two result files\n\n"
"Commands, options and reporting arrive with the later renderer\n"
"benchmark tickets."))
(defn- fail!
[message]
(js/console.error message)
;; Set the exit code instead of calling `process.exit` so piped output is
;; not truncated; nothing else keeps the process alive.
(set! (.-exitCode js/process) 1))
(defn -main
[& _]
(let [{:keys [options arguments errors summary]} (parse-opts (argv) cli-options)]
(cond
(:help options)
(println (usage summary))
(seq errors)
(fail! (str/join "\n" errors))
;; TODO(mem:render-wasm/performance/cljs-rewrite/10-process-build-and-server,
;; mem:render-wasm/performance/cljs-rewrite/11-runner-and-failure-accounting,
;; mem:render-wasm/performance/cljs-rewrite/14-custom-measured-operations):
;; dispatch `run`, `ab` and `compare` instead of failing.
(seq arguments)
(fail! (str "Unknown command: " (str/join " " arguments) "\nTry --help"))
:else
(fail! "No command given\nTry --help"))))