psiho / jsbench-me

jsbench.me - JavaScript performance benchmarking playground
140 stars 2 forks source link

Run hangs on deferred test, can't find variable from setup and abort doesn't work #26

Closed seymar closed 4 years ago

seymar commented 4 years ago

https://jsbench.me/czkc3zi7nf/1

One test has been set to defer and the test hangs on it. Console says it cannot find a variable from the setup. ReferenceError: Can't find variable: a

Also the abort function doesn't work, after aborting the page has to be refreshed to re-run the test.

Browsers: Safari, Chrome

psiho commented 4 years ago

do you have a link to the problematic test? I'm just a few days from publishing rewritten v1 and would certainly like to test this before golive.

seymar commented 4 years ago

See line 1 :-)

psiho commented 4 years ago

:)))) it's 2:20 AM here. I think it's time to stop :) will take a look tomorrow :)

psiho commented 4 years ago

Ah, quickly.... Check https://jsbench.me/rbizlulhi9 example of deffered (async code) tests. Those require deferred.resolve() and code to be async. You can check benchmark.js docs. JSbenchme is just a nice UI for it.

However this is a bug. App should never hang

psiho commented 4 years ago

I though about this and it will not go into v1, not sure for future. JSBenchme is a frontend to benchmark.js and for async tests deferred.resolve() is required to trigger test end. So behavior is by design of Benchmark.js. If there is no deferred.resolve(), it cannot know when the test is finished. It expects tests are written correctly. The only way around this would be to try and detect errors in code, search for deferred.resolve() in code in tests marked with "defer" checkbox and warn user if none is found. But even that is not bulletproof, as this text can be used in comments or improperly. That would require some compiler-like code and right there we go to far.

I want simple and fast tester and try to avoid bloating it as much as possible. It's not made for general public but for programmers, so understanding this behavior (never ending loop) and what caused it should not be an issue to most.