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

WorkerTransfer benchmark 3x slower on main compared to v2.1.1 #981

Closed
wipfli opened this issue Feb 10, 2022 · 22 comments
Closed

WorkerTransfer benchmark 3x slower on main compared to v2.1.1 #981

wipfli opened this issue Feb 10, 2022 · 22 comments
Labels

Comments

@wipfli
Copy link
Contributor

wipfli commented Feb 10, 2022

The WorkerTransfer benchmarks is 3x slower on main compared to v2.1.1.

@HarelM @birkskyum, might recent changes have something to do with this?

Steps to reproduce:

git checkout main
npm ci
npm run benchmark -- WorkerTransfer

                          v2.1.1      main 0263cc0 
 WorkerTransfer      19.9715 ms⚠️       93.1357 ms      +73.1641 ms
@wipfli
Copy link
Contributor Author

wipfli commented Feb 10, 2022

Yes, this is more like a factor of 4.5. But last time I run it, it was 30 ms. Would be helpful if someone could run this command and post the benchmark results here. Maybe it is machine-specific...

@birkskyum
Copy link
Member

birkskyum commented Feb 10, 2022

Hmm.. the commits that potentially could be involved off the top of my head would be #976, #974, #968. They were all merged recently.

We should probably figure this out and cut a new release soon, as a lot has happened since the last patch release.

@HarelM
Copy link
Collaborator

HarelM commented Feb 10, 2022

#941 also comes to mind as it adds another type to web worker transfer, which is exactly that test. ?

@HarelM
Copy link
Collaborator

HarelM commented Feb 10, 2022

I agree we should release a new version soon, I doubt that changing the worker code that was a simple replacement of file would've affected the performance, but everything is possible... :-)

@birkskyum
Copy link
Member

@birkskyum
Copy link
Member

or on cli npm run benchmark -- WorkerTransfer

@HarelM
Copy link
Collaborator

HarelM commented Feb 10, 2022

See my comment here:
#913 (comment)
I see this error in the console, I think it is related to this #913 PR...
Can anyone confirm this is not only happening to me?

@wipfli
Copy link
Contributor Author

wipfli commented Feb 10, 2022

Happened to me too.

@birkskyum
Copy link
Member

birkskyum commented Feb 10, 2022

But that was merged before 2.1.1, which seems to perform okay, but it could still be origin of the warnings.
release211

@HarelM
Copy link
Collaborator

HarelM commented Feb 10, 2022

It's a different issue, I don't think it is related to the worker transfer performance, or 2.1.1 is faster because this fails fast :-)

@HarelM
Copy link
Collaborator

HarelM commented Feb 10, 2022

This probably needs a bisect... :-( too late for me though...

@birkskyum
Copy link
Member

I found something... checking out the commit from v 2.1.1, and somehow it's different from v2.1.1 column.

211-vs-main-vs-211

The third colum is commit (f47e53c), and it should really be the same as the first.

@HarelM
Copy link
Collaborator

HarelM commented Feb 10, 2022

If we uploaded a generated benchmark file that doesn't properly use the web worker might it explain it?
I think we should test against an older version maybe?

@HarelM
Copy link
Collaborator

HarelM commented Feb 10, 2022

I'm talking about this PR: #704

@HarelM
Copy link
Collaborator

HarelM commented Feb 11, 2022

I wanted to see if this happens also in previous version, and I'm getting the following results:
npm run benchmark -- WorkerTransfer --compare v1.15.2 --compare v2.1.1

                            1.x cb3a420                    v2.1.1  move-bench-dirty 99107f3 
 WorkerTransfer              16.4234 ms                95.4176 ms               101.4773 ms 

npm run benchmark -- WorkerTransfer --compare v2.1.0 --compare v2.1.1

                                 v2.1.0                    v2.1.1  move-bench-dirty 99107f3 
 WorkerTransfer              16.6740 ms                98.1929 ms               106.5554 ms

So it seems that for some reason the first run is very fast but the next runs are not. I don't have a clue what can cause this though.

@birkskyum
Copy link
Member

birkskyum commented Feb 11, 2022

My current hypothesis is that workers are created for the first run, but never terminated, and thus maybe blocking them from launching in the other runs. So if I'm not mistaken, this indicates that web workers make a huge difference, and we could in principle release 2.1.2 and expect it to have the same performance as 2.1.1.

@HarelM
Copy link
Collaborator

HarelM commented Feb 11, 2022

I think we should release 2.1.2, even today.
We need to iron out any issues that might have been introduced from the build changes before we release the 3D. The community will hopefully help in that aspect.

@birkskyum
Copy link
Member

I have investigated a bit, and the only way the worker poll is being terminated is through:

Map._updateStyle() > Style._remove(); > Dispatcher.remove(); > WorkerPool.release()

So if we could also release the worker pool after each benchmark, that would probably help.

@birkskyum
Copy link
Member

Also, I tried to add a worker.terminate() in the WorkerTransfer teardown function, as we should clean it up properly.

@birkskyum
Copy link
Member

birkskyum commented Feb 11, 2022

All the map workers start when we trigger

function loadScript(src) {
            return new Promise((resolve, reject) => {
                const s = document.createElement('script');
                s.src = src;
                s.onload = resolve;
                s.onerror = reject;
                document.head.appendChild(s);
            });
        }

It would be much easier if we could use the maplibre api directly from the benchmarks, instead of going through benchmarks_generated.js

@HarelM
Copy link
Collaborator

HarelM commented Feb 11, 2022

Yup, see #982 .
But it's not an easy task as the current implementation checks the performance deep into the library code which is very powerful.

@github-actions
Copy link
Contributor

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.

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

No branches or pull requests

3 participants