Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathfinder Speed #139

Open
Pazaz opened this issue Aug 26, 2023 · 4 comments
Open

Pathfinder Speed #139

Pazaz opened this issue Aug 26, 2023 · 4 comments

Comments

@Pazaz
Copy link
Contributor

Pazaz commented Aug 26, 2023

@ultraviolet-jordan notes that supporting a full 2k world won’t be ideal due to pf speed (note that in real world cases not every player is generating a path every tick). We’re not expecting more than double-digit players and local development, which runs without issue.

Napkin benchmark: 100k paths, 10 tiles away - ~3000ms in TS, ~434ms in reference Kotlin implementation.

I think we can figure out JS/TS-specific optimizations and/or move pathfinder to native code. Jagex did client-side pathfinding at the time and evaluated steps from those generated paths on the server instead.

@dginovker
Copy link

dginovker commented Aug 26, 2023

If you can break down the inputs/outputs of pathfinding like a Leetcode question I can write a hyper efficient algorithm

@thedaneeffect
Copy link

I'm wondering how much of a speed improvement using a different JavaScript engine would give. Bun for example instead of Node. I don't know how incompatible that change would be though.

@Pazaz
Copy link
Contributor Author

Pazaz commented Sep 28, 2023

Definitely curious about Bun as well, but only supporting WSL on Windows is a no-go for contributors right now (can't guarantee everyone is on macOS/Linux!). It might be worth writing a small experiment to compare the different engines still.

@ultraviolet-jordan
Copy link
Collaborator

We've just converted the RSMod PathFinder from TypeScript to WebAssembly and these are the final before and after results doing 100,000 path requests in a single tick as the benchmark.

The Hardware

AMD Ryzen 9 3900X 12-Core Processor 3.80 GHz

Testing Location

image

The Command

We perform 100,000 path requests from this spot to a tile +10 tiles North.

            case 'bench': {
                const start = Date.now();
                for (let index = 0; index < 100_000; index++) {
                    World.pathFinder.findPath(this.level, this.x, this.z, this.x, this.z + 10);
                }
                const end = Date.now();
                console.log(`took = ${end - start} ms`);
                break;
            }

TypeScript Results (Before)

[0] took = 3858 ms
[0] took = 3855 ms
[0] took = 3828 ms
[0] took = 3820 ms
[0] took = 3833 ms
[0] took = 3852 ms
[0] took = 3844 ms

WebAssembly Results (After)

[0] took = 1534 ms
[0] took = 1540 ms
[0] took = 1544 ms
[0] took = 1519 ms
[0] took = 1533 ms
[0] took = 1522 ms
[0] took = 1527 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants