refactor(fiber): optimize reader enqueue
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
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.
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.
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% │
└───────────────────────────────────────────────────────────────┴──────────┴─────────┴────────────┘
Benchmark at #6067
Thanks! So, looks like around a 2% improvement. Not too bad!