Skip to content

Performance penalty for Log.debug #38

Description

@djones6

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions