Level / levelup

A wrapper for abstract-leveldown compliant stores, for Node.js and browsers.
MIT License
4.08k stars 266 forks source link

NotFoundError performance #739

Closed ronag closed 1 year ago

ronag commented 2 years ago

Creating an Error for "NotFound" instead of just returning null has a significant performance overhead. Creating Error objects are expensive.

Could we have a mode flag where we can avoid this?

ralphtheninja commented 2 years ago

Is this a real issue somewhere?

vweevers commented 2 years ago

Some time later I want to remove the (IMO usually unhelpful) error and return undefined instead. Per https://github.com/Level/community/issues/76.

@ronag For the short term, I'd say pull requests to make this behavior opt-in are welcome, but it does depend on which modules you're using. You'll also have to touch any implementation of abstract-leveldown that you're using, because levelup merely wraps the errors. If this involves too many modules, I'm reluctant to accept PRs, because I want to wind down the maintenance of these, in favor of abstract-level.

vweevers commented 2 years ago

Quick and dirty benchmark of error (!undef) vs undefined:

get 1645997866994

vweevers commented 1 year ago

https://github.com/Level/abstract-level/pull/49