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 penalty for Log.debug #38

Open
djones6 opened this issue Nov 7, 2018 · 1 comment
Open

Performance penalty for Log.debug #38

djones6 opened this issue Nov 7, 2018 · 1 comment

Comments

@djones6
Copy link
Contributor

djones6 commented Nov 7, 2018

Kitura's detailed logging is applied sparingly at present (we don't do much logging), because there is a small overhead to a log statement. Having many of these on the critical path hurts performance measurably.

Even though log statements wrap the message String in an @autoclosure (#18), the arguments still have to get passed through to a call (that then typically does nothing). This includes default values of #file, #function as well as the creation of the closure itself.

There are a couple of things we could try in this area:

  • We could provide alternate versions of 'expensive' log levels (verbose, debug, entry, exit) which can be used to disable those levels at compile time, for example:
#if PRODUCTION
    public class func debug(_ msg: @autoclosure () -> String, functionName: String = "",
                            lineNum: Int = 0, fileName: String = "") {
        return
    }
#else
(existing implementation)
#endif
  • Swift 4.2 introduces an @inlinable attribute which would allow calls to an empty function (like the above) to be completely eliminated.
@djones6
Copy link
Contributor Author

djones6 commented Nov 7, 2018

6da1ddf is an implementation of the above (only compiles on Swift 4.2 due to the use of @inlinable).

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

1 participant