LoggerAPI icon indicating copy to clipboard operation
LoggerAPI copied to clipboard

Performance penalty for Log.debug

Open djones6 opened this issue 7 years ago • 1 comments

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 avatar Nov 07 '18 15:11 djones6

https://github.com/IBM-Swift/LoggerAPI/commit/6da1ddfdd80e3279f42d7bab7c536df8ab8e2785 is an implementation of the above (only compiles on Swift 4.2 due to the use of @inlinable).

djones6 avatar Nov 07 '18 15:11 djones6