There is a long delay for dispatchEvent to trigger mousedown events.

problem description

dispatchEvent takes a long time to propagate mousedown events.

ele1.addEventListener("mousedown", dispatch);
function dispatch(e){
  console.log(new Date().getTime()); // time1
  var event = new e.constructor(e.type, e);
  ele2.dispatchEvent(event);
  console.log(new Date().getTime()); // time2 
}
The value of

time2-time1 is proportional to the number of elements, and the more elements, the higher the value, the higher the delay in firing mousedown events. Up to a few thousand milliseconds.

the environmental background of the problem

there are three parallel div layers, the outermost layer is the mask layer, the middle layer is the presentation layer, and the innermost layer is the event layer. The mask listens for mouse events, receives them and distributes them to the innermost layer using dispatchEvent. However, when there are many elements in the middle layer, there will be a high delay for mousedown events on the mask layer to call dispatchEvent propagation. The more middle-tier elements, the more time dispatchEvent takes and the higher the latency. The middle layer is not involved in event propagation.

--

After thinking about it for a long time, I didn"t understand it. I asked the boss for an answer. By the way, only mousedown has this problem, not even, mousemove, mousein, mouseout!

-- Update

this problem occurs only when the innermost layer is Amap, and there is no such problem in normal div.

Oct.09,2021
The reason for the delay in

is that there are too many nodes under the current dom. There is a delay when chrome handles a large number of nodes, firefox does not, but firefox loads slowly.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b379b8-4ed10.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b379b8-4ed10.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?