koin icon indicating copy to clipboard operation
koin copied to clipboard

Inline log function with message lambda

Open octa-one opened this issue 3 years ago • 6 comments

Minor improvement. When calling log(level: Level, msg: () -> MESSAGE) function with an inline modifier, no lambda object is created. This will slightly improve performance. I also removed canLog(...) function, because it is completely similar to the isAt(...) function.

octa-one avatar Jan 13 '22 13:01 octa-one

what about perf impact? I'm always worried about impact as such level

arnaudgiuliani avatar Feb 09 '22 13:02 arnaudgiuliani

Sorry for late reply. What do you mean about performance impact? If we add an inline modifier, as I suggest, Kotlin compiler will place the condition if (isAt(level)) { } from the function body at the call site, and will not create an extra instance for the lambda in function arguments.

Less object will be created, which will have a positive effect on performance, especially considering that logging is called quite often.

octa-one avatar Feb 27 '22 20:02 octa-one

Need to check in our latest version of Kotlin, but string evaluation could be done even if the string is in a lambda: like log() { "a message here" }. The message could be even evaluated. This is what we don't want, as the logs that aren't already inlined (because there's is already an API for that) mustn't evaluate messages that could provide heavier information load.

arnaudgiuliani avatar Mar 22 '22 07:03 arnaudgiuliani

Didn’t change anything, forgot that I already have 2 branches with pull requests.

octa-one avatar May 07 '22 15:05 octa-one

why this PR is still not merged? what does stop this?

ANIKINKIRILL avatar Sep 02 '22 19:09 ANIKINKIRILL

It's planned for 3.3.0 as part of new internal. Then, not released for 3.2.1 where we bring fixes only & library patch updates.

arnaudgiuliani avatar Sep 07 '22 08:09 arnaudgiuliani

Log API has been revamped https://github.com/InsertKoinIO/koin/blob/core/3.3.0/core/koin-core/src/commonMain/kotlin/org/koin/core/logger/Logger.kt

Thanks for your proposal. Feel free to reopen discussion on new API

arnaudgiuliani avatar Dec 13 '22 08:12 arnaudgiuliani