online icon indicating copy to clipboard operation
online copied to clipboard

calc perf: GetEmptyLinesInBlock

Open mmeeks opened this issue 2 years ago • 5 comments

From this week's calc flamegraph:

https://user-images.githubusercontent.com/833656/271274520-6345ee72-2a06-402e-a12c-72bd8d49df8d.svg

Shows a chunk of rendering time is calling:

image

GetEmptyLinesInBlock - we should examine that in some detail to see why :-)

mmeeks avatar Sep 29 '23 14:09 mmeeks

sc/source/ui/view/output2.cxx:void ScOutputData::DrawEdit(bool bPixelToLogic) ... //! store nLastContentCol as member! SCCOL nLastContentCol = mpDoc->MaxCol(); if ( nX2 < mpDoc->MaxCol() ) nLastContentCol = sal::static_int_cast<SCCOL>( nLastContentCol - mpDoc->GetEmptyLinesInBlock( nX2+1, nY1, nTab, mpDoc->MaxCol(), nY2, nTab, DIR_RIGHT ) );

A useful comment there to store the nLastContentCol I guess ...

mmeeks avatar Sep 29 '23 14:09 mmeeks

Essentially duplicate logic in ScOutputData::LayoutStrings - doing the same thing; I guess MaxCol() increases bites us hard here too: in all 40% of the time in DrawContent and 25% of the paintPartTile time is scanning columns to the right to look for content ...

mmeeks avatar Sep 29 '23 14:09 mmeeks

source/core/data/column2.cxx:SCSIZE ScColumn::GetEmptyLinesInBlock( SCROW nStartRow, SCROW nEndRow, ScDirection eDir ) const ... sc/source/core/data/column2.cxx- std::pairsc::CellStoreType::const_iterator,size_t aPos = maCells.position(nStartRow);

Seems to be using only the maCells - data storage; and we -should- have a document-wide maximum for this already stored in: ScTable's mnEndCol (I expect):

sc/source/core/data/table1.cxx-bool ScTable::GetCellArea( SCCOL& rEndCol, SCROW& rEndRow )

And I expect that mnEndCol <<< MaxCol() which should let us significantly speed this up.

@eszkadev I'm interested in how mnEndCol is maintained though - I'd expect to see more invalidation of mbCellAreaDirty as data is written into the document, but perhaps I miss something.

mmeeks avatar Sep 29 '23 14:09 mmeeks

data area is invalidated here: https://opengrok.libreoffice.org/xref/core/sc/source/ui/unoobj/docuno.cxx?r=2f85eb7a#3298

eszkadev avatar Oct 02 '23 07:10 eszkadev

@sopyb this might be an interesting one to look at too - quite some code pointers; I expect that its necessary to have a sheet with a lot of columns that get created perhaps in error to play with, perhaps @grandinj has an idea of a good test sheet to reproduce this before digging into it deeper ? =)

mmeeks avatar Oct 01 '24 21:10 mmeeks