Is there some courses about WASM on improving bjs performance?
What’s your use case?
WASM is already used in some parts of the Babylon.js codebase, where it makes sense, like for physics simulation.
It’s really only going to be beneficial for some very specific use cases, in my opinion.
1 Like
I’m not an expert in WASM, and a few days ago, instead of looking for a course I gave a try to Grok in think mode : impressive !
The goal was to compute pear to pear distances in a custom heavy point cloud (for each point I need distance to all other points… A classic N²
problem). The algo is as simple as a double for loop. Here was the first output of Grok (no diagonal optimisation)
C code :
#include <math.h>
#include <stdlib.h>
void compute_squared_distances(const double* points, int n, double* distances) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
double dx = points[i * 2] - points[j * 2];
double dy = points[i * 2 + 1] - points[j * 2 + 1];
distances[i * n + j] = sqrt(dx * dx + dy * dy);
}
}
}
Command to compile :
emcc distances.c -o distances.js -s EXPORTED_FUNCTIONS='["_compute_squared_distances", "_malloc", "_free"]' -s EXPORTED_RUNTIME_METHODS='["HEAPF64"]' -s MODULARIZE=1 -s ENVIRONMENT='web' -O2
Result :
- A
distances.wasm
file - A
distances.js
file (module) to import the compiled function
I didn’t expect WASM to be that easy, thanks AIs
5 Likes