levelup icon indicating copy to clipboard operation
levelup copied to clipboard

NotFoundError performance

Open ronag opened this issue 2 years ago • 3 comments

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?

ronag avatar Feb 27 '22 19:02 ronag

Is this a real issue somewhere?

ralphtheninja avatar Feb 27 '22 20:02 ralphtheninja

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 avatar Feb 27 '22 21:02 vweevers

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

get 1645997866994

vweevers avatar Feb 27 '22 21:02 vweevers

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

vweevers avatar Nov 08 '22 14:11 vweevers