I had a brief discussion with @jfmc about the performance of the WASM version. Jose claims a difference of about 2 times compared to the naive version. For SWI-Prolog this is closer to 10 times. Jose suspected threaded code may be problematic. Threaded code is a trick where the VM instructions are direct addresses into the VM code dispatching switch. So, I promised to check. Well, SWI-Prolog has three modes for compiling the VM:
- A classical switch.
- Threaded code
- Compile each instruction to a function. Now the function pointer is used as VM instruction. This is the default for the WASM version as it builds the fastest and ran the fastest when the WASM port materialized.
But, things have changed. Using Emscripted 4.0.15 (latest) and node v22.19.0 (Fedora 42), we get
- A classical switch: 0.38 sec
- Threaded code: 0.38 sec
- VM functions: 0.61 sec
So, I think we should switch. Unfortunately the first two crash on one of the tests