Add MOZ_UNLIKELY to if branch in MOZ_TRY macro
Categories
(Core :: MFBT, enhancement, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox71 | --- | fixed |
People
(Reporter: arai, Assigned: arai)
Details
Attachments
(1 file, 1 obsolete file)
#define MOZ_TRY(expr) \
do { \
auto mozTryTempResult_ = ::mozilla::ToResult(expr); \
if (mozTryTempResult_.isErr()) { \
return ::mozilla::Err(mozTryTempResult_.unwrapErr()); \
} \
} while (0)
IMO, the isErr()
case is almost always error case and not-hot code path.
adding MOZ_UNLIKELY
should improve the generated code.
in BinAST parser (that heavily used MOZ_TRY
macro and variants), adding MOZ_UNLIKELY
notably improves the performance (~3% speed up with parsing 200 files)
Impressive!
Maybe we should also add it to other cases in Result.h, like all those isOk() ? x : y
lines.
Comment 2•6 years ago
|
||
Or perhaps isOk()
itself could return MOZ_LIKELY(...)
instead of ...
. It does not seem unreasonable to me to impose upon Result
the intended semantic that the success case be normal and errors be irregular.
Comment 3•6 years ago
|
||
(And of course isErr()
would return MOZ_UNLIKELY(...)
, and whatever other relevant functions that could use similar treatment would get it.)
Comment 4•6 years ago
|
||
(In reply to Tooru Fujisawa [:arai] from comment #0)
in BinAST parser (that heavily used
MOZ_TRY
macro and variants), addingMOZ_UNLIKELY
notably improves the performance (~3% speed up with parsing 200 files)
That'd be a case for adding something that uses the BinAST parser to the PGO profile.
Assignee | ||
Comment 5•6 years ago
|
||
Depends on D48021
Comment 6•6 years ago
|
||
bool isOk() const { return MOZ_LIKELY(mImpl.isOk()); }
...
bool isErr() const { return MOZ_UNLIKELY(!mImpl.isOk()); }
Does clang know how to optimize the caller code when a function returns MOZ_LIKELY
or MOZ_UNLIKELY
? Do you still see the same ~3% speed up as you do when using MOZ_UNLIKELY
in the MOZ_TRY
macro directly?
Assignee | ||
Comment 7•6 years ago
|
||
(In reply to Chris Peterson [:cpeterson] from comment #6)
bool isOk() const { return MOZ_LIKELY(mImpl.isOk()); }
...
bool isErr() const { return MOZ_UNLIKELY(!mImpl.isOk()); }Does clang know how to optimize the caller code when a function returns
MOZ_LIKELY
orMOZ_UNLIKELY
? Do you still see the same ~3% speed up as you do when usingMOZ_UNLIKELY
in theMOZ_TRY
macro directly?
thanks for pointing out. you're right. it doesn't work as I expect.
will post fixed one.
Updated•6 years ago
|
Assignee | ||
Comment 8•6 years ago
|
||
Comment 10•6 years ago
|
||
bugherder |
Description
•