Kitura / Kitura/LoggerAPI

Performance penalty for Log.debug

Open
#38 1 comment 0 reactions 1 assignee Claimed by @adam-rocska View on GitHub
Dominant language
Swift
Stars
29
Forks
23
PR merge metrics
No merged PRs in 30d

Description

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:
```swift
#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](https://github.com/apple/swift-evolution/blob/master/proposals/0193-cross-module-inlining-and-specialization.md) attribute which would allow calls to an empty function (like the above) to be completely eliminated.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.