Random optimizations#9657
Conversation
|
Nay for the dbg.is_on branches (it hampers readability too much for the very meager gains it offers (if any), the only meaningful logging-related branch we have that passes that benchmark is the input event parsing one), yay for the rest ;). |
| function WakeupMgr:getWakeupAlarmSys() | ||
| return RTC:getWakeupAlarmSys() | ||
| end | ||
| WakeupMgr.getWakeupAlarmSys = RTC.getWakeupAlarmSys |
There was a problem hiding this comment.
That won't work because RTC is not a module-local, IIRC (it can be overloaded by the constructor).
There was a problem hiding this comment.
I see a problem: Calling WakeupMgr:getWakeupAlarmSys() will call RTC.getWakeupAlarmSys(self), but I also see that self is not used in RTC.getWakeupAlarmSys (in ffi/rtc.lua).
So it is OK but not ultra clean to use WakeupMgr.getWakeupAlarmSys = RTC.getWakeupAlarmSys. But if we want to be ultra clean we should also rewrite RTC:getWakeupAlarmSys() to RTC.getWakupAlarmSys()
Is that the problem you are adressing here or are you maybe confusing somthing like
koreader/frontend/device/kindle/powerd.lua
Line 255 in 60a16c7
local RTC = require("ffi/rtc")) (and can't be overloaded by anything). ???(It has been my original intention: Use
grep -RPzo "\nfunction.*\(\)\n .*\(\)\nend\n" frontend/ to find wrappers and replace them. But it was obvious that self.something can not be optimized, so only a few methods remained.)
There was a problem hiding this comment.
I was thinking of the rtc = RTC in the constructor, but you raise another interesting concern, too, so, yeah, I'd forget about this one ;).
(LuaJIT is very good at tail-call optimizations anyway).
There was a problem hiding this comment.
So I will leave this change in, and I am looking forward to the solution of the "interesting concern".
| -- use our own main loop | ||
| if not self.looper then | ||
| while self._running do | ||
| repeat |
There was a problem hiding this comment.
I abhor repeat constructs.
And a while makes much more sense here, because we do want to check the condition first.
There was a problem hiding this comment.
I accept you personal decision about repeat-until constructs (as here there is no real performance drawback :) ). (But we set self._running to true a few lines above, so repeat-until would be OK.)
There was a problem hiding this comment.
I'd rather figure out a way to actually remove the whole _running & _run_forever stuff altogether, because it feels a little gadgety ;).
|
Ready to merge? |
NiLuJe
left a comment
There was a problem hiding this comment.
Another random thought about using aliases for Event handlers: beware of the return value (because it controls propagation).
(Not an issue here given the type of events in question ;)).
Reviewed 2 of 4 files at r1, 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @poire-z and @zwim)
frontend/ui/uimanager.lua line 1105 at r3 (raw file):
if self._window_stack[i].widget.covers_fullscreen then start_idx = i if dbg.is_on and i > 1 then
Forgot this one ;).
Frenzie
left a comment
There was a problem hiding this comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @NiLuJe and @poire-z)
frontend/ui/uimanager.lua line 1105 at r3 (raw file):
Previously, NiLuJe (NiLuJe) wrote…
Forgot this one ;).
Logic suggests it should be a touch faster that way than having logger.dbg decide the same thing, assuming that's backed up by profiling.
NiLuJe
left a comment
There was a problem hiding this comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Frenzie and @poire-z)
frontend/ui/uimanager.lua line 1105 at r3 (raw file):
Previously, Frenzie (Frans de Jonge) wrote…
Logic suggests it should be a touch faster that way than having logger.dbg decide the same thing, assuming that's backed up by profiling.
Possibly, but if nothing else than for consistency's sake, those concerns are left to logger unless the gains are obvious (c.f., my earlier comment about the verbose input event decodes) ;).
ghost
left a comment
There was a problem hiding this comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @NiLuJe and @poire-z)
frontend/ui/uimanager.lua line 1105 at r3 (raw file):
Previously, NiLuJe (NiLuJe) wrote…
Possibly, but if nothing else than for consistency's sake, those concerns are left to logger unless the gains are obvious (c.f., my earlier comment about the verbose input event decodes) ;).
Yeah, it would be faster with ad dbg.is_on check, but not really noticeable.
I would say we just should keep in mind that for all logger.xxx calls the arguments are always evaluated, even if the function itself is a noop.
For this special case I have no strong opinion to keep if dbg.is_on or drop it. We have a similar construct in Line 202 (but there the logger call before the if costs more so hmm, I would drop it.
Frenzie
left a comment
There was a problem hiding this comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @NiLuJe and @poire-z)
frontend/ui/uimanager.lua line 1105 at r3 (raw file):
Previously, zwim wrote…
Yeah, it would be faster with ad
dbg.is_oncheck, but not really noticeable.
I would say we just should keep in mind that for alllogger.xxxcalls the arguments are always evaluated, even if the function itself is a noop.For this special case I have no strong opinion to keep
if dbg.is_onor drop it. We have a similar construct in Line 202 (but there the logger call before theifcosts more so hmm, I would drop it.
I'm not entirely sure what you mean by special case. If it makes no appreciable performance difference it's not a special case to me. ;-)
ghost
left a comment
There was a problem hiding this comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @NiLuJe and @poire-z)
frontend/ui/uimanager.lua line 1105 at r3 (raw file):
Previously, Frenzie (Frans de Jonge) wrote…
I'm not entirely sure what you mean by special case. If it makes no appreciable performance difference it's not a special case to me. ;-)
"This special case" was just a saying and meant nothing special (huh). Exactly spoken I meant in this "this context".
Frenzie
left a comment
There was a problem hiding this comment.
Reviewable status: 3 of 4 files reviewed, 2 unresolved discussions (waiting on @NiLuJe and @poire-z)
frontend/ui/uimanager.lua line 1105 at r3 (raw file):
Previously, zwim wrote…
"This special case" was just a saying and meant nothing special (huh). Exactly spoken I meant in this "this context".
Specific? ^_^
ghost
left a comment
There was a problem hiding this comment.
Reviewable status: 3 of 4 files reviewed, 2 unresolved discussions (waiting on @NiLuJe and @poire-z)
frontend/ui/uimanager.lua line 1105 at r3 (raw file):
Previously, Frenzie (Frans de Jonge) wrote…
Specific? ^_^
I don't want to fool you. But I think we have a communication problem ;-)
I wanted to say:
1.) I would drop it and
2.) don't forget that arguments of functions are always evaluated.
There was a problem hiding this comment.
Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Frenzie and @poire-z)
frontend/ui/uimanager.lua line 1105 at r3 (raw file):
Previously, zwim wrote…
I don't want to fool you. But I think we have a communication problem ;-)
I wanted to say:
1.) I would drop it and
2.) don't forget that arguments of functions are always evaluated.
Yeah, that's kind of my reasoning for dropping it ;).
Namely: the argument.. argument ;p doesn't hold here as they're relatively trivial; the main issue is the fact that it's the sole call behind a dedicated branch...
And that we indeed have two similar constructs, so handling only one doesn't make sense ;).
(Not that I'm advocating for handling both, although I do understand the motivation. I'm mostly against it so as not to set a precedent when it's for such trivial branching).
NiLuJe
left a comment
There was a problem hiding this comment.
Reviewed 3 of 3 files at r5, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Frenzie and @poire-z)
|
Some issues caused by this PR: #9569 (comment) , #9741. |
|
Thanks, not that I can recall. I will fix that. |
This should fix koreader#9741.
This PR implements two different things:
logger.dbgbehinddbg.is_on. This saves evaluation of thelogger.dbgarguments, (Power)The PR should
Dunno if this PR is desired. If not, pleas close.
This change is