Open Bug 1933557 Opened 4 days ago Updated 3 days ago

new Map([[fiber, expirationTime]]) is 7x slower than Chrome, affects scheduleWork on TodoMVC-React-Redux

Categories

(Core :: JavaScript Engine, defect)

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%.

Summary: new Map([[fiber, expirationTime]]) is 7x slower than Chrome, affect scheduleWork on TodoMVC-React-Redux → new Map([[fiber, expirationTime]]) is 7x slower than Chrome, affects scheduleWork on TodoMVC-React-Redux
Blocks: speedometer3
Whiteboard: [sp3]

Calling Map/Set with an argument is exactly the case I didn't fully optimize yet :) Some thoughts:

  1. 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 for Map. At least if the length is small (like in this case) then checking IsPackedArray for each element is definitely much faster than calling into self-hosted code.

  2. 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-hosted MapConstructorInit or SetConstructorInit 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.

Flags: needinfo?(jdemooij)
Whiteboard: [sp3] → [sp3][js-perf-next]
You need to log in before you can comment on or make changes to this bug.