new Map([[fiber, expirationTime]]) is 7x slower than Chrome, affects scheduleWork on TodoMVC-React-Redux
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
People
(Reporter: mstange, Unassigned, NeedInfo)
References
(Blocks 1 open bug)
Details
(Whiteboard: [sp3][js-perf-next])
After the work in bug 1851662, creating Map
and Set
objects has mostly disappeared from the sp3 comparison profiles.
The one remaining instance I found was scheduleWork
on TodoMVC-React-Redux, which does new Map([[fiber, expirationTime]])
:
function scheduleWork(fiber, expirationTime) {
if (50 < nestedUpdateCount) throw nestedUpdateCount = 0, rootWithNestedUpdates = null, Error(formatProdErrorMessage(185));
fiber = markUpdateTimeFromFiberToRoot(fiber, expirationTime);
if (null !== fiber) {
var priorityLevel = getCurrentPriorityLevel();
1073741823 === expirationTime ? (executionContext & LegacyUnbatchedContext) !== NoContext && (executionContext & (RenderContext | CommitContext)) === NoContext ? performSyncWorkOnRoot(fiber) : (ensureRootIsScheduled(fiber), executionContext === NoContext && flushSyncCallbackQueue()) : ensureRootIsScheduled(fiber);
(executionContext & 4) === NoContext || 98 !== priorityLevel && 99 !== priorityLevel || (null === rootsWithPendingDiscreteUpdates ? rootsWithPendingDiscreteUpdates = new Map([[fiber, expirationTime]]) : (priorityLevel = rootsWithPendingDiscreteUpdates.get(fiber), (void 0 === priorityLevel || priorityLevel > expirationTime) && rootsWithPendingDiscreteUpdates.set(fiber, expirationTime)));
}
}
Profiles:
Firefox: https://share.firefox.dev/3B0jqjO
Chrome: https://share.firefox.dev/4eJAbhb (7x faster)
Fixing this difference would improve Firefox's score on TodoMVC-React-Redux by 1.2% and Firefox's overall sp3 score by 0.1%.
Reporter | ||
Updated•4 days ago
|
Reporter | ||
Updated•4 days ago
|
Updated•4 days ago
|
Comment 1•3 days ago
|
||
Calling Map
/Set
with an argument is exactly the case I didn't fully optimize yet :) Some thoughts:
-
The
Set
constructor has a fast path for packed arrays where it avoids calling from C++ into self-hosted code. We should probably do something similar forMap
. At least if the length is small (like in this case) then checkingIsPackedArray
for each element is definitely much faster than calling into self-hosted code. -
Ideally we'd also do the
Map
/Set
object allocation in JIT code in this case. Then we could do a VM call to either initialize the object in C++, or return a value that means "call the self-hostedMapConstructorInit
orSetConstructorInit
function directly from JIT code".
I'll try to get to this the coming weeks. It's probably pretty common and 1.2% on React-Redux is worth it.
Updated•3 days ago
|
Description
•