Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use optional chaining to optimize logging #3411

Closed
dapplion opened this issue Nov 4, 2021 · 1 comment
Closed

Use optional chaining to optimize logging #3411

dapplion opened this issue Nov 4, 2021 · 1 comment
Labels
prio-medium Resolve this some time soon (tm). scope-performance Performance issue and ideas to improve performance.

Comments

@dapplion
Copy link
Contributor

dapplion commented Nov 4, 2021

Optional chaining only runs code at the next step of a property chain if it's defined. We could use this property to prevent running debug code with minimal syntax boilerplate. For example:

function forever() {
  while (true) {}
}
const logger = {}

logger.debug?.(forever())

A more realistic example would look like

logger.debug?.("Some data", {
  root: expensiveComputation(data)
})

And we set logger.debug = undefined if logger level is greater than debug

@dapplion dapplion added the scope-performance Performance issue and ideas to improve performance. label Nov 4, 2021
@philknows philknows added the prio-medium Resolve this some time soon (tm). label Nov 29, 2021
@dapplion
Copy link
Contributor Author

Looked into implementing this and the semantics are ugly in practice. I've also reviewed all statements under info log level and there's nothing too expensive, 99% are string template-ing and plain objects which are very cheap to instantiate. Given that the logger bleeds into almost every module of the lodestar namespace I don't think the pros are worth to cons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio-medium Resolve this some time soon (tm). scope-performance Performance issue and ideas to improve performance.
Projects
None yet
Development

No branches or pull requests

2 participants