maraisr / diary

📑 Zero-dependency, fast logging library for Node, Browser and Workers
MIT License
255 stars 7 forks source link

perf: boost 🚀 #1

Closed lukeed closed 3 years ago

lukeed commented 3 years ago

Notes

Feedback

AKA, not implemented

I think your hooks API might feel a bit better if you didn't return within every hook; and instead just expect mutations. You can use return false as a stop/bailout.

middleware((logEvent) => {
  events.push(logEvent);
--  return logEvent;
}, suite);

I didn't add this since it would be a breaking change – previous undefined, even implicit ones, would cause the diary loop to stop, whereas my suggestion would treat that as the normal case.

Before

Benchmark
  diary      x 366,134 ops/sec ±0.54% (95 runs sampled)
  debug      x 234,103 ops/sec ±2.14% (88 runs sampled)
  pino       x 51,023 ops/sec ±2.07% (92 runs sampled)
  winston    x 12,874 ops/sec ±3.00% (84 runs sampled)

After

Benchmark
  diary      x 664,120 ops/sec ±1.30% (87 runs sampled)
  debug      x 227,989 ops/sec ±0.91% (91 runs sampled)
  pino       x 51,160 ops/sec ±1.76% (94 runs sampled)
  winston    x 13,116 ops/sec ±2.90% (94 runs sampled)
lukeed commented 3 years ago

(force push after rebase)

The test is failing exactly because of my allows changes. The test is changing the process.env.DEBUG value at runtime. If this is intentional, I can revert the eager hoisting, which still puts performance around 420k to 430k op/s