trentm/node-bunyan — pull request #113 by tonistiigi (2013-12-05 21:26:08+00:00)
Title: Make condition queries faster

Initial benchmark shows ~700x improvement.

It doesn't use sandbox so its not 100% compatible with previous version but I think its very hard to accidentally leak anything. On the other hand it now allows combining conditions for some complex queries.

I started with a version that uses `new Function()` instead of `eval`. https://github.com/tonistiigi/node-bunyan/compare/master...condition-function In my opinion its cleaner but in this version condition needs to be a Javascript expression. So instead on `if()` you would have to use `?:` etc. (dtrace users should be used to this). Anyway, it also turned out to be slower than `eval`. The slow part is the assignment of `__proto__` for the log level definitions, without it its faster than `eval`.

##### Benchmark results:

Tested on a real log file with 1k/30k rows. Conditions matched for ~5% of the rows.

Original 1k rows: **12.557s** [flamegraph](https://us-east.manta.joyent.com/tonistiigi/public/bunyan-bench/00-original.svg)
Eval 30k rows: **0.449s** [flamegraph](https://us-east.manta.joyent.com/tonistiigi/public/bunyan-bench/02-eval.svg)
Function 30k rows: **0.551s** [flamegraph](https://us-east.manta.joyent.com/tonistiigi/public/bunyan-bench/01-function.svg)
Eval no dunder proto 30k rows: **0.424s** [flamegraph](https://us-east.manta.joyent.com/tonistiigi/public/bunyan-bench/02-eval-noproto.svg)
Function no dunder proto 30k rows: **0.390s** [flamegraph](https://us-east.manta.joyent.com/tonistiigi/public/bunyan-bench/01-function-noproto.svg)