OnBlockCountChange called cumulatively on first load
fareesh opened this issue · 3 comments
I have an existing Sir Trevor document with 31 blocks
sir-trevor-js/src/block-positioner.js
Line 35 in 4e1a20a
Due to this line, on first load, the renderPositionList
seems to be called (1..n) times x 31 times, which slows down loading significantly for larger documents.
For documents with 100+ blocks, loading time seems to take 30+ seconds
Since I am not using the position list, I have removed that line for my usage.
Is the following considered typical behaviour for an existing document?
-
On first load,
createBlocks
creates each block in the data store -
Each block, when added, triggers
block:countUpdate
which triggersonBlockCountChange
with the new count -
onBlockCountChange
calls renderPositionList, which loops from 0.. new block count. -
If 31 blocks are added, the above does DOM manipulation of the select position list n times from 1 to 31, i.e. 1+2+3+4...31 times = 528. For larger documents e.g. 155 blocks, this is 12,090 DOM manipulations.
Or, is my page triggering these events too many times for some other reason? I am running with a the latest version with all the default initialization parameters.
Stumbled upon this problem with a document containing ~600 blocks. Load time is insane.
If I'm reading code right, onBlockCountChange
is called per block.
So, ~600 blocks will result in ~180000 renderPositionList
calls
Updated and merged an existing pr which amends the working for this.