Skip to content

Enhance benchmarking - #12332

Closed
FilipAndersson245 wants to merge 7 commits into
nushell:mainfrom
FilipAndersson245:enhance_benchmarking
Closed

FilipAndersson245 wants to merge 7 commits into
nushell:mainfrom
FilipAndersson245:enhance_benchmarking

Conversation

@FilipAndersson245

@FilipAndersson245 FilipAndersson245 commented Mar 29, 2024 •

Copy link
Copy Markdown
Contributor

Description

closes #12331

This PR does 3 things

  • changes divan to a specific commit to enable file exports.
  • sets a min_time for each current bench, this to reduce noise for fast benches.
  • Adds a few new commands to toolkit.nu,
    • format-benchmark-data: convert the benchmark data from divan to a simple flat table.
    • compare-benchmarks: takes 2 different benchmarks and try to generate a simple report comparing them.

image

User-Facing Changes

Tests + Formatting

After Submitting

@FilipAndersson245 FilipAndersson245 changed the title Enhance benchmarking, closes #12331 Enhance benchmarking Mar 29, 2024
Comment thread Cargo.toml Resolved
@fdncred

fdncred commented Mar 30, 2024

Copy link
Copy Markdown
Contributor

Just one comment above but I'm fine with the rest of the PR. I just don't want this change to cause our publishing to puke.

@FilipAndersson245

Copy link
Copy Markdown
Contributor Author

If someone in core could help me test this out it would be appreciated 👏

@FilipAndersson245

Copy link
Copy Markdown
Contributor Author

I changed the default comparason metric from median to fastest based on this

@FilipAndersson245

Copy link
Copy Markdown
Contributor Author

Im trying to rewrite this PR and instead using the main branch of divan and instead try to parse down the graphical output from divan.

@kubouch

kubouch commented Apr 1, 2024

Copy link
Copy Markdown
Contributor

I checked it, and it seems we can't publish a crate with unpublished dependencies, so the git link won't work.

It is a bit unfortunate that divan development has slowed down. Last commit was 2 months ago and divan's PR implementing file output hasn't yet received any maintainer comments despite being open since January. We can roll with your parsing script, but if divan ends up being unmaintained, we might need to switch back to criterion or something that's at least somewhat maintained.

@FilipAndersson245

FilipAndersson245 commented Apr 1, 2024 •

Copy link
Copy Markdown
Contributor Author

I checked it, and it seems we can't publish a crate with unpublished dependencies, so the git link won't work.

It is a bit unfortunate that divan development has slowed down. Last commit was 2 months ago and divan's PR implementing file output hasn't yet received any maintainer comments despite being open since January. We can roll with your parsing script, but if divan ends up being unmaintained, we might need to switch back to criterion or something that's at least somewhat maintained.

I have a new script that parses the raw output, in the oven, probably try to get it in this PR, so we don`t have to use a PR.

But yee divan does not seem quite as active as one could hope as of now. I'm open to the idea of moving back as more tools support criterion, but I enjoy the simplified benchmarking on divian more. Criterion also is not as active as one could wish for.

@FilipAndersson245

Copy link
Copy Markdown
Contributor Author

@fdncred @kubouch I have tried out a new approach that relies on parsing the visual printout of divan, I think its decent, but may break if they change their format.

The new markdown display format

Name Old New Relative Note
load_standard_lib 8ms 502µs 8ms 502µs 1
decoding_benchmarks
  json_decode
   (100, 5) 406µs 200ns 406µs 200ns 1
   (10000, 15) 157ms 100µs 157ms 100µs 1
  msgpack_decode
   (100, 5) 179µs 100ns 179µs 100ns 1
   (10000, 15) 63ms 720µs 63ms 720µs 1
encoding_benchmarks
  json_encode
   (100, 5) 87µs 280ns 87µs 280ns 1
   (10000, 15) 21ms 50µs 21ms 50µs 1
  msgpack_encode
   (100, 5) 35µs 400ns 35µs 400ns 1
   (10000, 15) 9ms 212µs 9ms 212µs 1
eval_benchmarks
  eval_default_config 2ms 216µs 2ms 216µs 1
  eval_default_env 347µs 400ns 347µs 400ns 1
eval_commands
  each
   1 51µs 51µs 1
   5 267µs 400ns 267µs 400ns 1
   10 489µs 400ns 489µs 400ns 1
   100 5ms 339µs 5ms 339µs 1
   1000 53ms 560µs 53ms 560µs 1
  for_range
   1 51µs 320ns 51µs 320ns 1
   5 266µs 266µs 1
   10 532µs 100ns 532µs 100ns 1
   100 5ms 247µs 5ms 247µs 1
   1000 53ms 150µs 53ms 150µs 1
  interleave
   100 420µs 400ns 420µs 400ns 1
   1000 3ms 943µs 3ms 943µs 1
   10000 38ms 730µs 38ms 730µs 1
  interleave_with_ctrlc
   100 421µs 100ns 421µs 100ns 1
   1000 3ms 784µs 3ms 784µs 1
   10000 40ms 650µs 40ms 650µs 1
  par_each_1t
   1 69µs 340ns 69µs 340ns 1
   5 285µs 400ns 285µs 400ns 1
   10 517µs 900ns 517µs 900ns 1
   100 5ms 405µs 5ms 405µs 1
   1000 53ms 300µs 53ms 300µs 1
  par_each_2t
   1 77µs 750ns 77µs 750ns 1
   5 189µs 200ns 189µs 200ns 1
   10 304µs 700ns 304µs 700ns 1
   100 2ms 785µs 2ms 785µs 1
   1000 26ms 750µs 26ms 750µs 1
parser_benchmarks
  parse_default_config_file 1ms 397µs 1ms 397µs 1
  parse_default_env_file 247µs 100ns 247µs 100ns 1
record
  create
   1 20µs 560ns 20µs 560ns 1
   10 31µs 240ns 31µs 240ns 1
   100 138µs 300ns 138µs 300ns 1
   1000 1ms 229µs 1ms 229µs 1
  flat_access
   1 11µs 210ns 11µs 210ns 1
   10 11µs 890ns 11µs 890ns 1
   100 19µs 100ns 19µs 100ns 1
   1000 99µs 590ns 99µs 590ns 1
  nest_access
   1 11µs 640ns 11µs 640ns 1
   2 11µs 950ns 11µs 950ns 1
   4 13µs 820ns 13µs 820ns 1
   8 18µs 470ns 18µs 470ns 1
   16 26µs 980ns 26µs 980ns 1
   32 57µs 960ns 57µs 960ns 1
   64 178µs 600ns 178µs 600ns 1
   128 678µs 300ns 678µs 300ns 1
table
  create
   1 23µs 710ns 23µs 710ns 1
   10 35µs 870ns 35µs 870ns 1
   100 156µs 900ns 156µs 900ns 1
   1000 1ms 368µs 1ms 368µs 1
  get
   1 16µs 340ns 16µs 340ns 1
   10 19µs 580ns 19µs 580ns 1
   100 50µs 90ns 50µs 90ns 1
   1000 335µs 500ns 335µs 500ns 1
  select
   1 15µs 480ns 15µs 480ns 1
   10 22µs 30ns 22µs 30ns 1
   100 79µs 50ns 79µs 50ns 1
   1000 646µs 300ns 646µs 300ns 1

Nushell record look

image

@kubouch

kubouch commented Apr 1, 2024

Copy link
Copy Markdown
Contributor

Would it be possible to modify the output to not contain the empty entries? It could be made into a tree structure, or added as a prefix, e.g., encoding_benchmarks::json_decode::(100, 5), encoding_benchmarks::json_decode::(10000, 5), etc.

Otherwise, I think we could roll with this and see how it goes with divan's development in the future.

@FilipAndersson245

FilipAndersson245 commented Apr 1, 2024 •

Copy link
Copy Markdown
Contributor Author

I think this works fine, i am not to sure how to format the data correctly for that.

I think this fits nicely in github markdown table.

@kubouch

kubouch commented Apr 1, 2024

Copy link
Copy Markdown
Contributor

It looks fine, but it's harder to do any processing with it. But we can keep it as-is, since it's still an improvement over having no parsing. The suggestion I made can be added later as another postprocessing step, for example.

@FilipAndersson245

Copy link
Copy Markdown
Contributor Author

I am thinking on what you said @kubouch and maybe Criterion would be better, in the least part cause it so standardized in the community. And would most likely live on in some form in the longterm.

@kubouch

kubouch commented Apr 2, 2024

Copy link
Copy Markdown
Contributor

Yeah, divan seems really cool, but is more uncertain than criterion. We could switch back to criterion and see what happens with divan.

@FilipAndersson245

Copy link
Copy Markdown
Contributor Author

Yeah, divan seems really cool, but is more uncertain than criterion. We could switch back to criterion and see what happens with divan.

My only problem is that the maintenance, status of Criterion is quite uncertain also, as the main contributor have not committed in almost 2 years. I am becoming inspired to write my own 😎.

@kubouch

kubouch commented Apr 2, 2024

Copy link
Copy Markdown
Contributor

Haha, that's the way :-D. Maybe it would be worth checking with the divan maintainer and perhaps offering help with the maintenance instead of starting from scratch.

The main plus of criterion is being able to get some structured data out of it (e.g., JSON). I've been playing with ideas of how to set up continuous benchmark tracking, but it's quite essential to be able to reliably output structured data. If we could get the JSON PR landed to divan, we could just continue using divan as long as it works in the current form.

@FilipAndersson245

Copy link
Copy Markdown
Contributor Author

yee, I like divans simpler sapling strategy that allows it to be a lot faster compared to criterion. But it fell criterion relayed more on robust statistics when describing their results. divan is more 👁️ statistics.

@FilipAndersson245

Copy link
Copy Markdown
Contributor Author

I have create an alternative PR where i migrate the benchmarks back to criterion, but after the talk jon had, that was linked in the weekly meeting I have started to try out tango.rs and it seem very interesting, it works by compiling two versions of a program and comparing them. I may explore if that would be a better alternative. As I am not that sold on criterion either as it's slow and not as robust as it gives the shine of.

@fdncred

fdncred commented Apr 9, 2024

Copy link
Copy Markdown
Contributor

where are we at on the benchmarks? does this pr need to land for the alternate or are we chosing between the two?

@FilipAndersson245

FilipAndersson245 commented Apr 9, 2024 •

Copy link
Copy Markdown
Contributor Author

@fdncred
It depend, I have done some talks with the author of Tango, as I had some initial difficulties using it in nutshell but it seems to be my fault for failing to detect our existing build.rs

We have 3 options,

  1. Stay with what we have now. I think this works decent, only sad part is that we are a bit locked out of making nice data collecting.
  2. I have created an alternative PR, that moves all existing benchmarks from this back to criterion.
  3. We move to tango, which still is quite actively developed, but I fell this pair-benchmarking provide something quite nice in terms of evaluating performance.

I am personally quite annoyed about how slow criterion is and how it says its statistically significant changes but I fell quite often I see random multi digit changes between run. Tango seem both faster and more stable as what I can see, It also seem to already support file exports, And is actively maintained.

I was initially made aware of Tango from Jon Gjengset latest Rust Talk.

@FilipAndersson245
FilipAndersson245 marked this pull request as draft April 10, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Divan benchmarking tracking

3 participants