-
-
Notifications
You must be signed in to change notification settings - Fork 241
refactor: call tracer only after isEnabled check #1500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
original PR: #958
test |
traceLog(`NativeScriptAnimationPlayer.play`); | ||
if (isLogEnabled()) { | ||
traceLog(`NativeScriptAnimationPlayer.play`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sis0k0 just curious - couldn't this perhaps just be called in tracer itself to avoid having to have these conditionals all over the codebase? ie:
import { isEnabled } from "tns-core-modules/trace";
export function animationsLog(message: string): void {
if (isEnabled()) {
write(message, animationsTraceCategory);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The disadvantage of having the check inside the tracer itself is that this will result in two function calls - one for animationsLog
and one for isEnabled
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if the check was inside the animationsLog
function and we invoked animationsLog("something" + random)
, we would have the overhead of the string concatenation as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explanation makes sense :) Perhaps there’s a possibility we could also add something to webpack config to strip these all out in production mode as well to coincide with this pr. Ideally with the whole trace enabler control we should probably have ways that devs can strip them when desired as well since keeping core libs slim and performant as possible is always highest goal (which thank you for attention to that here!).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great idea! 10x :)
For anyone that comes across this PR and is also wondering @NathanaelA provided an additional explanation which is very helpful: Performance. Take this example :
By calling
It is always recommended to check if you can log before blindly calculating and logging. Logging can be expensive; especially if any of the do?() functions are expensive... For those who have trace logging enabled in that area to debug something; the ms time used that occurs to run the isEnabled() check is tiny compared to the actual log command. So they don't experience any slow down by doing it that way.. |
Thank you, @NathanWalker, for taking the time to explain this in detail! |
original PR: #958