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

Performance when disabled #1

Closed
ThomasGHenry opened this issue Apr 10, 2019 · 3 comments
Closed

Performance when disabled #1

ThomasGHenry opened this issue Apr 10, 2019 · 3 comments

Comments

@ThomasGHenry
Copy link

This looks awesome! If I wanted this in place for development and test, turned off in production, and only flipped on and off via config, what's the impact to performance in production (while disabled)?

So, say the stuff is all there, it's just off, is there a performance hit? Is every method checking the config and choosing not to log at runtime, or is the injection just not performed in the first place? Or...?

Thanks!

@aigoncharov
Copy link
Owner

@LogClass wraps your class with a Proxy. Proxies are pretty fast nowadays. Yet it's still going to look up the config metainformation, it's still going to build the message and pass it to the logger of your choice. But that's how most of the loggers work, right? You can change the logging level, but the logic is still there. Anyway, I wouldn't expect it to be a massive performance hit.
If you're not convinced with the argument you can wrap LogClass decorator with your own implementation that will disable it conditionally:

import { LogClass as LogClassOriginal, IClassLoggerConfig } from 'class-logger'

export const LogClass = (config: IClassLoggerConfig) => {
  if (process.env.NODE_ENV === 'production') { // It can be any condition you want
    return () => undefined // return an empty decorator placeholder
  }
  return LogClassOriginal(config)
} 

@LogClass()
class Test {}

This would prevent your class being wrapped with a Proxy, therefore no performance impact at all.

@libinvarghese
Copy link

It would be great if the above info was part of README.md

@aigoncharov
Copy link
Owner

@libinvarghese makes sense.
https://github.com/aigoncharov/class-logger#proxy-performance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants