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

WasmJs: in a batch consisting of multiple benchmark functions the first one is always runs faster #197

Open
fzhinkin opened this issue Mar 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@fzhinkin
Copy link
Contributor

While analyzing the performance of some Kotlin stdlib functions, I faced the following issue: when running wasmJs benchmarks, the first benchmark among the batch always runs faster.

Consider the following example:

@Benchmark fun a(blackhole: Blackhole) { blackhole.consume(1) }
@Benchmark fun b(blackhole: Blackhole) { blackhole.consume(2) }
@Benchmark fun c(blackhole: Blackhole) { blackhole.consume(3) }

All three functions are identical (module the numeric literal), but when benchmarked, a is always faster:

Benchmark                 Mode  Cnt  Score   Error  Units
BenchmarkWithBlackhole.a  avgt    5  4.961 ± 0.006  ns/op
BenchmarkWithBlackhole.b  avgt    5  9.036 ± 0.023  ns/op
BenchmarkWithBlackhole.c  avgt    5  9.034 ± 0.022  ns/op

If the first function is excluded and now the run consists of only two benchmarks, the one executed earlier will be faster again:

Benchmark                 Mode  Cnt   Score   Error  Units
BenchmarkWithBlackhole.b  avgt    5   5.250 ± 0.032  ns/op
BenchmarkWithBlackhole.c  avgt    5  11.328 ± 0.051  ns/op

The issue is not reproducible with js target.

You can find a demo project here: https://github.com/fzhinkin/kotlinx-benchmark-wasmjs-issue

@fzhinkin fzhinkin added the bug Something isn't working label Mar 28, 2024
@fzhinkin
Copy link
Contributor Author

I tried to analyze V8 logs (I have no expertise in that area), but didn't find anything that could explain performance degradation after the first benchmark execution finished.

fzhinkin added a commit to fzhinkin/kt-64361-benchmarks that referenced this issue Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant