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.

Activity

  1. djones6 commented on Nov 7, 2018

    @djones6
    ContributorAuthor

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

  2. self-assigned this
    on May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions