I made recalculateFollowDistances async, it now processes in batches of 1000 and uses queueMicrotask

Reply to this note

Please Login to reply.

Discussion

Looks like that helped a lot. also I was calling the recalculate method every few seconds and it looks like thats not nessisary... so thats a x2 improvement right there :)

The only thing thats still causing the page to freeze is deserializing the graph. it takes about 3s on my machine

I haven't looked into it too much, but it looks like its the follow distance calculation that is taking the longest. do you think it would make sense to store the distance in the serialized graph in order to speed up load times?

This givee me an idea

OpenAI o3 optimized the recalc method, should be faster now. Also changed queueMicrotask to setTimeout, which might block less.

Consecutive calls to recalc while it's still in progress now return the same promise instead of starting a new operation