M
M
Magneto9032021-03-24 18:40:21
C++ / C#
Magneto903, 2021-03-24 18:40:21

Pathfinding algorithm (eg Dijkstra) on WebAssembly?

I want to solve 2 problems:
Find the distance from a specific point (let's say point A) to all other points in the graph
Restore the best (with the smallest length) from point A to any point in the graph

In my opinion, Dijkstra's algorithm is suitable here. However, I need to solve these tasks on the frontend and in the web application. JavaScript is too slow for this task. I've heard that webassembly is very fast, often almost as fast as code (eg in C/C++) from which it was compiled into wasm, which is clearly faster than JavaScript.

I wrote a program myself to solve these 2 problems in C (taking into account the fact that this will have to compile to wasm) (however this is not Dijkstra's explicit form, but rather a modification of the breadth-first search algorithm for weighted graphs, or you can say, that this is Dijkstra with a queue where the vertex can get there more than once) I 'm attaching this code
just in case Unfortunately, if it is compiled in wasm, it works quite slowly, and even slower than native JS. (For 160+ vertices and 350+ edges, the speed is more than 1ms) Perhaps something is wrong with the C code. (Collected in wasm through this service )

But I'm interested in the question, is it possible to write an implementation faster in wasm? (If there are ready-made implementations, I would be very grateful if you tell me about them) What speed can I expect?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question