TritonDataCenter / node-verror

Rich JavaScript errors
MIT License
1.18k stars 61 forks source link

Do not call sprintf with zero argument #61

Closed hekike closed 5 years ago

hekike commented 5 years ago

Calling sprintf is expensive, do not call when zero arguments are passed. In some scenarios, an application needs to create hundreds of VError(s).

To test the change's effect:

for(var i = 0; i < 10000; i++) {
        new mod_verror.VError('Foo')
}

On my 2017 MBP 3.5Ghz, I see a 27% performance improvement after the change.

Before: screen shot 2018-12-31 at 10 29 47 am

hekike commented 5 years ago

https://github.com/joyent/node-verror/issues/63 https://cr.joyent.us/#/c/5299/