Skip to content

perf: optimize .child#2300

Merged
jsumners merged 2 commits intopinojs:mainfrom
ronag:child-opt
Oct 2, 2025
Merged

perf: optimize .child#2300
jsumners merged 2 commits intopinojs:mainfrom
ronag:child-opt

Conversation

@ronag
Copy link
Copy Markdown
Contributor

@ronag ronag commented Sep 28, 2025

benchmark                   avg (min … max) p75 / p99    (min … top 1%)
------------------------------------------- -------------------------------
pino child creation          174.95 ns/iter  87.23 ns █                    
                       (63.07 ns … 5.76 µs)   3.60 µs █                    
                    ( 53.17  b …   8.62 kb) 261.17  b █▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

pino2 child creation         257.64 ns/iter 330.37 ns █                    
                       (67.99 ns … 7.37 µs)   4.49 µs █▂                   
                    ( 22.38  b …   5.82 kb) 266.57  b ██▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
// bench.mjs

import { bench, run } from 'mitata'

import pino from './pino.js'
import pino2 from 'pino'

let logger = pino().child({ b: 'property' })
const children = []

bench('pino child creation', function () {
  children.push(logger.child({ a: 'property' }))
})

let logger2 = pino().child({ b: 'property' })
const children2 = []

bench('pino2 child creation', function () {
  children2.push(logger2.child({ a: 'property' }))
})

await run()

children[Math.random() * children.length | 0].info({ hello: 'world' })

Comment thread lib/proto.js
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work

Comment thread lib/proto.js
Comment thread lib/tools.js
Comment thread lib/proto.js
Copy link
Copy Markdown
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I'd just like a comment added to explain the optimization for future readers.

Comment thread lib/proto.js
Co-authored-by: James Sumners <321201+jsumners@users.noreply.github.com>
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jsumners jsumners merged commit d11abf5 into pinojs:main Oct 2, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants