dune icon indicating copy to clipboard operation
dune copied to clipboard

refactor(fiber): optimize reader enqueue

Open rgrinberg opened this issue 3 years ago • 4 comments

we know that case [Empty_with_readers] has at least one job to enqueue, so we enqueue it manually ourselves before enqueuing the rest.

Signed-off-by: Rudi Grinberg [email protected]

ps-id: de9dbcec-fc09-426c-a9e2-811f5f38f430

rgrinberg avatar Aug 05 '22 17:08 rgrinberg

We already have a benchmark for this. Unfortunately, it's a little hard to measure it in this case.

With this PR:

┌───────────────────────────────────┬──────────┬─────────┬──────────┬──────────┬────────────┐
│ Name                              │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────────────────┼──────────┼─────────┼──────────┼──────────┼────────────┤
│ [bench/micro/fiber_bench.ml] ivar │  34.23us │ 59.06kw │   13.64w │   13.64w │    100.00% │
└───────────────────────────────────┴──────────┴─────────┴──────────┴──────────┴────────────┘

Without this PR:

┌───────────────────────────────────┬──────────┬─────────┬──────────┬──────────┬────────────┐
│ Name                              │ Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────────────────┼──────────┼─────────┼──────────┼──────────┼────────────┤
│ [bench/micro/fiber_bench.ml] ivar │  34.61us │ 59.06kw │   13.64w │   13.64w │    100.00% │
└───────────────────────────────────┴──────────┴─────────┴──────────┴──────────┴────────────┘

So the improvement is quite tiny. Though we shouldn't have expected much from this optimization.

rgrinberg avatar Aug 08 '22 19:08 rgrinberg

Hmm, 30us (a huge time scale!) suggests that this benchmark isn't a great fit for this specific change. I'd expect to see nanosecond scale timings.

snowleopard avatar Aug 10 '22 11:08 snowleopard

Added a simpler benchmark. With PR:

┌───────────────────────────────────────────────────────────────┬──────────┬─────────┬────────────┐
│ Name                                                          │ Time/Run │ mWd/Run │ Percentage │
├───────────────────────────────────────────────────────────────┼──────────┼─────────┼────────────┤
│ [bench/micro/fiber_bench.ml] create ivar and immediately read │  64.49ns │  91.00w │    100.00% │
└───────────────────────────────────────────────────────────────┴──────────┴─────────┴────────────┘

Without PR:

┌───────────────────────────────────────────────────────────────┬──────────┬─────────┬────────────┐
│ Name                                                          │ Time/Run │ mWd/Run │ Percentage │
├───────────────────────────────────────────────────────────────┼──────────┼─────────┼────────────┤
│ [bench/micro/fiber_bench.ml] create ivar and immediately read │  65.92ns │  91.00w │    100.00% │
└───────────────────────────────────────────────────────────────┴──────────┴─────────┴────────────┘

rgrinberg avatar Aug 11 '22 04:08 rgrinberg

Benchmark at #6067

rgrinberg avatar Aug 11 '22 04:08 rgrinberg

Thanks! So, looks like around a 2% improvement. Not too bad!

snowleopard avatar Aug 12 '22 00:08 snowleopard