These arrays are very small, and the filtering logic is very simple. I think in this case it's to be expected that doing it in JS is much faster compared to having to call some external code and incurring whatever overhead associated with doing so. If the array length was in the thousands, tens of thousands or more, and the filtering logic was complex, I could see the WASM solution being faster. I think you have the right idea to do heavy tasks in WASM, but the task in this example is very light.
Arrays in general are allocated pretty quickly as it's just a contiguous block of memory, and the allocation time between something like length 8 vs length 8k is not likely to matter much in the grand scheme of things if only done once or a couple of times.
Try more complex data, e.g. composed of various nested types (each of which must be instantiated separately), or something much more computationally expensive.
Okay, I will try, but in a real case, I don't think that in frontend side we do something much more computationally expensive, this will be the role of Backend or BFF (like graphql). I don't see very well the added value of WASM in frontend side.
Here's an example of a pretty cool Wasm project to showcase what it's capable of: https://wasm.continuation-labs.com/d3demo/
If you're only doing things that are already normally taken care of by the frontend the value of Wasm is probably not that high. One thing to consider is that you could potentially move some of the computation done in the backend to the frontend and lighten the load on the server.
A good comparison might be parallelism: it can provide a big speedup in some cases, but in simple cases the overhead just ends up slowing the entire thing down.
I have done only some frontend usual tasks, if I choose to move some backend parts inside frontend, I will have a very huge bundle that will take tooooooo long time to be downloaded especially for devices with some poor performances.
Yeah I loved safety when using Rust + WASM (everything is check before frontend consumption) but I will loose performance.
I don't think that Rust + WASM are suitable for frontend apps that doesn't do 3D, image/video processing, VR, ... Even for these apps we should compare to see the added value.
Thank you so much for all your answer and contribution. I understand now very well when WASM and when not !