CollaboraOnline / online

Collabora Online is a collaborative online office suite based on LibreOffice technology. This is also the source for the Collabora Office apps for iOS and Android.
https://collaboraonline.com
Other
1.78k stars 680 forks source link

Moving image perf. issue #6148

Open mmeeks opened 1 year ago

mmeeks commented 1 year ago

If you move an image with alpha images in the document you can end up on this slow path:

 signal SIGINT, Interrupt.
0x00007f59f92dd670 in fetch_and_convert_pixel (format=<optimized out>, offset=<optimized out>, bits=<optimized out>, image=<optimized out>) at pixman-access.c:293
293     return a | r | g | b;
(gdb) bt
#0  0x00007f59f92dd670 in fetch_and_convert_pixel (format=<optimized out>, offset=<optimized out>, bits=<optimized out>, image=<optimized out>) at pixman-access.c:293
#1  fetch_pixel_r8g8b8 (image=0x7c1c9f0, offset=0, line=<optimized out>) at pixman-access.c:479
#2  0x00007f59f92e7256 in fetch_pixel_no_alpha_32 (image=image@entry=0x7c1c9f0, x=x@entry=0, y=y@entry=357, check_bounds=check_bounds@entry=1, out=out@entry=0x7ffeab48a8b0) at pixman-bits-image.c:53
#3  0x00007f59f92e76f3 in bits_image_fetch_pixel_separable_convolution (image=image@entry=0x7c1c9f0, x=<optimized out>, x@entry=64750, y=<optimized out>, y@entry=23388499, get_pixel=get_pixel@entry=0x7f59f92e7220 <fetch_pixel_no_alpha_32>, out=out@entry=0x7ffeab48abe0, accum=accum@entry=0x7f59f92e72c0 <accum_32>, reduce=0x7f59f92e7300 <reduce_32>) at pixman-bits-image.c:397
#4  0x00007f59f92e9c0f in bits_image_fetch_pixel_filtered (out=0x7ffeab48abe0, get_pixel=0x7f59f92e7220 <fetch_pixel_no_alpha_32>, y=23388499, x=64750, wide=<optimized out>, image=<optimized out>) at pixman-bits-image.c:462
#5  __bits_image_fetch_affine_no_alpha (iter=0x7ffeab48aac0, wide=0, mask=0x7ffeab48b2b0) at pixman-bits-image.c:520
#6  0x00007f59f931f522 in general_composite_rect (imp=0x1a35610, info=<optimized out>) at pixman-general.c:227
#7  0x00007f59f92dc415 in pixman_image_composite32 (op=PIXMAN_OP_OVER, src=<optimized out>, mask=<optimized out>, dest=<optimized out>, src_x=-118, src_y=792, mask_x=-118, mask_y=792, dest_x=115, dest_y=2348, width=436, height=356) at pixman.c:700
#8  0x00007f59f93b3567 in composite_boxes () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#9  0x00007f59f94033ee in composite_aligned_boxes () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#10 0x00007f59f9403b1d in clip_and_composite_boxes () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#11 0x00007f59f9403ee5 in _cairo_spans_compositor_mask () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#12 0x00007f59f93a38e8 in _cairo_compositor_mask () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#13 0x00007f59f93bddfd in _cairo_image_surface_mask () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#14 0x00007f59f9413f39 in _cairo_surface_mask () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#15 0x00007f59f93ae0ec in _cairo_gstate_mask () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#16 0x00007f59f93a7901 in _cairo_default_context_mask () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#17 0x00007f59f94279a6 in cairo_mask () from /opt/libreoffice/co-22.05/instdir/program/libcairo-lo.so.2
#18 0x00007f59fcfa9156 in SvpSalGraphics::drawAlphaBitmap (this=0x889be20, rTR=..., rSourceBitmap=..., rAlphaBitmap=...) at /opt/libreoffice/co-22.05/vcl/headless/svpgdi.cxx:738
#19 0x00007f59fcc1ee21 in OutputDevice::DrawDeviceAlphaBitmap (this=this@entry=0xa981700, rBmp=..., rAlpha=..., rDestPt=Point = {...}, rDestSize=Size = {...}, rSrcPtPixel=Point = {...}, rSrcSizePixel=Size = {...}) at /opt/libreoffice/co-22.05/vcl/source/outdev/bitmap.cxx:345
#20 0x00007f59fcc1fd6c in OutputDevice::DrawDeviceBitmapEx (this=0xa981700, rDestPt=Point = {...}, rDestSize=Size = {...}, rSrcPtPixel=Point = {...}, rSrcSizePixel=Size = {...}, rBitmapEx=...) at /opt/libreoffice/co-22.05/vcl/source/outdev/bitmapex.cxx:175
#21 0x00007f59fcc1f737 in OutputDevice::DrawBitmapEx (this=0xa981700, rDestPt=Point = {...}, rDestSize=Size = {...}, rSrcPtPixel=Point = {...}, rSrcSizePixel=Size = {...}, rBitmapEx=..., nAction=MetaActionType::BMPEXSCALE) at /opt/libreoffice/co-22.05/vcl/source/outdev/bitmapex.cxx:145
#22 0x00007f59fcc1fad1 in OutputDevice::DrawBitmapEx (rBitmapEx=..., rDestSize=Size = {...}, rDestPt=Point = {...}, this=0xa981700) at /opt/libreoffice/co-22.05/vcl/source/outdev/bitmapex.cxx:66
#23 OutputDevice::DrawBitmapEx (this=0xa981700, rDestPt=Point = {...}, rDestSize=Size = {...}, rBitmapEx=...) at /opt/libreoffice/co-22.05/vcl/source/outdev/bitmapex.cxx:52
#24 0x00007f59fcc20f6d in OutputDevice::DrawTransformedBitmapEx (this=0xa981700, rTransformation=..., rBitmapEx=..., fAlpha=<optimized out>, fAlpha@entry=1) at /opt/libreoffice/co-22.05/vcl/source/outdev/bitmapex.cxx:556
#25 0x00007f59f9b9db88 in drawinglayer::processor2d::VclProcessor2D::RenderBitmapPrimitive2D (this=this@entry=0x697ddb0, rBitmapCandidate=...) at /opt/libreoffice/co-22.05/include/rtl/ref.hxx:206
#26 0x00007f59f9b96005 in drawinglayer::processor2d::VclPixelProcessor2D::processBitmapPrimitive2D (this=0x697ddb0, rBitmapCandidate=...) at /opt/libreoffice/co-22.05/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx:534
#27 0x00007f59f9b84bf9 in drawinglayer::processor2d::BaseProcessor2D::process (this=0x697ddb0, rSource=...) at /opt/libreoffice/co-22.05/drawinglayer/source/processor2d/baseprocessor2d.cxx:69
#28 0x00007f59f9b1ef09 in drawinglayer::primitive2d::BufferedDecompositionPrimitive2D::get2DDecomposition (this=0x886ea20, rVisitor=..., rViewInformation=...) at /opt/libreoffice/co-22.05/drawinglayer/source/primitive2d/BufferedDecompositionPrimitive2D.cxx:46
#29 0x00007f59f9b84bf9 in drawinglayer::processor2d::BaseProcessor2D::process (this=this@entry=0x697ddb0, rSource=...) at /opt/libreoffice/co-22.05/drawinglayer/source/processor2d/baseprocessor2d.cxx:69
#30 0x00007f59f9b99dc2 in drawinglayer::processor2d::VclProcessor2D::RenderMaskPrimitive2DPixel (this=0x697ddb0, rMaskCandidate=...) at /opt/libreoffice/co-22.05/drawinglayer/source/processor2d/vclprocessor2d.cxx:780
#31 0x00007f59f9b84bf9 in drawinglayer::processor2d::BaseProcessor2D::process (this=0x697ddb0, rSource=...) at /opt/libreoffice/co-22.05/drawinglayer/source/processor2d/baseprocessor2d.cxx:69
#32 0x00007f59f9b84bf9 in drawinglayer::processor2d::BaseProcessor2D::process (this=0x697ddb0, rSource=...) at /opt/libreoffice/co-22.05/drawinglayer/source/processor2d/baseprocessor2d.cxx:69
#33 0x00007f59f51bad61 in paintUsingPrimitivesHelper (rOutputDevice=..., rSequence=..., rSourceRange=..., rTargetRange=basegfx::B2DRange = {...}) at /usr/include/c++/11/bits/unique_ptr.h:173
#34 0x00007f59f51bd1c2 in paintGraphicUsingPrimitivesHelper (rOutputDevice=..., rContent=..., rGraphicTransform=..., rName="Image7", rTitle=..., rDescription="") at /opt/libreoffice/co-22.05/sw/source/core/doc/notxtfrm.cxx:994
#35 0x00007f59f51bddd9 in SwNoTextFrame::PaintPicture (this=0x6cc8960, pOut=0xa981700, rGrfArea=...) at /opt/libreoffice/co-22.05/sw/source/core/doc/notxtfrm.cxx:1274
#36 0x00007f59f51becbc in SwNoTextFrame::PaintSwFrame (this=0x6cc8960, rRenderContext=..., rRect=...) at /opt/libreoffice/co-22.05/sw/source/core/doc/notxtfrm.cxx:313
#37 0x00007f59f538f418 in SwLayoutFrame::PaintSwFrame (this=0x6a735b0, rRenderContext=..., rRect=SwRect = {...}) at /opt/libreoffice/co-22.05/sw/source/core/layout/paintfrm.cxx:3583
#38 0x00007f59f539328e in SwFlyFrame::PaintSwFrame (this=0x6a735b0, rRenderContext=..., rRect=...) at /opt/libreoffice/co-22.05/sw/source/core/layout/paintfrm.cxx:4285
#39 0x00007f59f5246a3c in SwVirtFlyDrawObj::wrap_DoPaintObject (this=0x6ada760, rViewInformation=...) at /opt/libreoffice/co-22.05/sw/source/core/draw/dflyobj.cxx:532
#40 0x00007f59f5246b1d in drawinglayer::primitive2d::(anonymous namespace)::SwVirtFlyDrawObjPrimitive::get2DDecomposition (this=0x764c1c0, rVisitor=..., rViewInformation=...) at /opt/libreoffice/co-22.05/sw/source/core/draw/dflyobj.cxx:233
#41 0x00007f59f9b84bf9 in drawinglayer::processor2d::BaseProcessor2D::process (this=0xb3d79f0, rSource=...) at /opt/libreoffice/co-22.05/drawinglayer/source/processor2d/baseprocessor2d.cxx:69
#42 0x00007f59fe43d9c3 in sdr::contact::ViewObjectContactOfSdrPage::getPrimitive2DSequenceHierarchy (this=0x758c330, rDisplayInfo=..., rVisitor=...) at /opt/libreoffice/co-22.05/svx/source/sdr/contact/viewobjectcontactofsdrpage.cxx:622
#43 0x00007f59fe464750 in sdr::contact::ObjectContactOfPageView::DoProcessDisplay (this=0x7864d00, rDisplayInfo=...) at /usr/include/c++/11/bits/unique_ptr.h:173
#44 0x00007f59fe4a3944 in SdrPageWindow::RedrawLayer (this=0x70bef70, pId=pId@entry=0x7ffeab4936ef, pRedirector=pRedirector@entry=0x7ffeab493990, pPageFrame=pPageFrame@entry=0x7ffeab493860) at /opt/libreoffice/co-22.05/svx/source/svdraw/sdrpagewindow.cxx:423
#45 0x00007f59fe59e6bd in SdrPageView::DrawLayer (this=0x6b4dd00, nID=..., nID@entry=..., pGivenTarget=pGivenTarget@entry=0xa981700, pRedirector=pRedirector@entry=0x7ffeab493990, rRect=..., pPageFrame=pPageFrame@entry=0x7ffeab493860) at /opt/libreoffice/co-22.05/svx/source/svdraw/svdpagv.cxx:265
#46 0x00007f59f5709bf5 in SwViewShellImp::PaintLayer (this=this@entry=0x72ac790, _nLayerID=..., pPrintData=pPrintData@entry=0x0, rPageFrame=..., aPaintRect=SwRect = {...}, _pPageBackgrdColor=_pPageBackgrdColor@entry=0x7ffeab493a00, _bIsPageRightToLeft=<optimized out>, pRedirector=<optimized out>) at /opt/libreoffice/co-22.05/sw/source/core/view/vdraw.cxx:148
#47 0x00007f59f539249b in SwRootFrame::PaintSwFrame (this=<optimized out>, rRenderContext=..., rRect=SwRect = {...}, pPrintData=pPrintData@entry=0x0) at /opt/libreoffice/co-22.05/sw/source/core/layout/paintfrm.cxx:3316
#48 0x00007f59f5713eb7 in SwViewShell::Paint (this=0x6b7fc10, rRenderContext=..., rRect=...) at /opt/libreoffice/co-22.05/sw/source/core/view/viewsh.cxx:1892
#49 0x00007f59f50907e6 in SwCursorShell::Paint (this=this@entry=0x6b7fc10, rRenderContext=..., rRect=...) at /opt/libreoffice/co-22.05/sw/source/core/crsr/crsrsh.cxx:1428
#50 0x00007f59f570f6d4 in SwViewShell::ImplUnlockPaint (this=this@entry=0x6b7fc10, bVirDev=bVirDev@entry=true) at /opt/libreoffice/co-22.05/include/rtl/ref.hxx:206
#51 0x00007f59f5363e05 in SwViewShell::UnlockPaint (bVirDev=true, this=0x6b7fc10) at /opt/libreoffice/co-22.05/sw/inc/viewsh.hxx:611
#52 SwLayIdle::SwLayIdle (this=0x7ffeab493e80, pRt=<optimized out>, pI=<optimized out>) at /opt/libreoffice/co-22.05/sw/source/core/layout/layact.cxx:2362
#53 0x00007f59f570ce26 in SwViewShell::LayoutIdle (this=<optimized out>) at /opt/libreoffice/co-22.05/sw/source/core/view/viewsh.cxx:776
#54 0x00007f59f516cb91 in sw::DocumentTimerManager::DoIdleJobs (this=0x6922d20) at /opt/libreoffice/co-22.05/sw/source/core/inc/rootfrm.hxx:207
#55 0x00007f59fce201a7 in Scheduler::CallbackTaskScheduling () at /opt/libreoffice/co-22.05/vcl/source/app/scheduler.cxx:478
#56 0x00007f59fcfaac9c in SalTimer::CallCallback (this=<optimized out>) at /opt/libreoffice/co-22.05/vcl/inc/saltimer.hxx:54
#57 SvpSalInstance::CheckTimeout (this=<optimized out>, bExecuteTimers=<optimized out>) at /opt/libreoffice/co-22.05/vcl/headless/svpinst.cxx:212
#58 0x00007f59fcfaadab in SvpSalInstance::DoYield (this=0x1b0b1b0, bWait=<optimized out>, bHandleAllCurrentEvents=<optimized out>) at /opt/libreoffice/co-22.05/vcl/headless/svpinst.cxx:457
#59 0x00007f59fce2e3c2 in ImplYield (i_bWait=i_bWait@entry=true, i_bAllEvents=i_bAllEvents@entry=false) at /opt/libreoffice/co-22.05/vcl/source/app/svapp.cxx:470
#60 0x00007f59fce2ec2c in Application::Yield () at /opt/libreoffice/co-22.05/vcl/source/app/svapp.cxx:537
#61 0x00007f59fce30995 in Application::Execute () at /opt/libreoffice/co-22.05/vcl/source/app/svapp.cxx:449
#62 0x00007f5a00eb9ccb in desktop::Desktop::Main (this=0x7ffeab494380) at /opt/libreoffice/co-22.05/desktop/source/app/app.cxx:1608
#63 0x00007f59fce396e9 in ImplSVMain () at /opt/libreoffice/co-22.05/vcl/source/app/svmain.cxx:199
#64 0x00007f5a00edf9df in soffice_main () at /opt/libreoffice/co-22.05/desktop/source/app/sofficemain.cxx:98
#65 0x00007f5a00ef3d52 in lo_runLoop (pPollCallback=0x5acf45 <pollCallback(void*, int)>, pWakeCallback=0x5acf89 <wakeCallback(void*)>, pData=0x67a5c30) at /opt/libreoffice/co-22.05/desktop/source/lib/init.cxx:7015
#66 0x00000000005baa19 in lok::Office::runLoop (this=0x67c46c0, pPollCallback=0x5acf45 <pollCallback(void*, int)>, pWakeCallback=0x5acf89 <wakeCallback(void*)>, pData=0x67a5c30) at /opt/libreoffice/co-22.05/include/LibreOfficeKit/LibreOfficeKit.hxx:1079
#67 0x00000000005b43d3 in lokit_main (childRoot="/opt/libreoffice/online-22.05/jails/", jailId="jLDUL2VaYbiqN65e", sysTemplate="/opt/libreoffice/online-22.05/systemplate", loTemplate="/opt/libreoffice/co-22.05/instdir", noCapabilities=false, noSeccomp=false, queryVersion=false, displayVersion=true, numericIdentifier=11) at kit/Kit.cpp:2987
#68 0x0000000000589031 in createLibreOfficeKit (childRoot="/opt/libreoffice/online-22.05/jails/", sysTemplate="/opt/libreoffice/online-22.05/systemplate", loTemplate="/opt/libreoffice/co-22.05/instdir", queryVersion=false) at kit/ForKit.cpp:411
#69 0x0000000000589d55 in forkLibreOfficeKit (childRoot="/opt/libreoffice/online-22.05/jails/", sysTemplate="/opt/libreoffice/online-22.05/systemplate", loTemplate="/opt/libreoffice/co-22.05/instdir", limit=0) at kit/ForKit.cpp:464
#70 0x000000000058dd29 in main (argc=9, argv=0x7ffeab49b358) at kit/ForKit.cpp:781
(gdb) up 51
#51 0x00007f59f5363e05 in SwViewShell::UnlockPaint (bVirDev=true, this=0x6b7fc10) at /opt/libreoffice/co-22.05/

he worst of it is that we don't want to be drawing anything at idle really; so right at the top of the stack:

The rot sets in here:

52 SwLayIdle::SwLayIdle (this=0x7ffeab493e80, pRt=, pI=) at /opt/libreoffice/co-22.05/sw/source/core/layout/layact.cxx:2362

...

// If there are accrued paints, it's best to simply invalidate // the whole window. Otherwise there would arise paint problems whose // solution would be disproportionally expensive. SwViewShellImp *pViewImp = rSh.Imp(); bool bUnlock = false; if ( pViewImp->HasPaintRegion() ) { pViewImp->DeletePaintRegion();

// Cause a repaint with virtual device.
rSh.LockPaint();
bUnlock = true;

} And the unlockPaint is the beast that causes the grief - so I expect that my patch here:

https://gerrit.libreoffice.org/c/core/+/149622

Would fix the performance problem - but ... this also causes some re-rendering regression it seems.

49 0x00007f59f50907e6 in SwCursorShell::Paint (this=this@entry=0x6b7fc10, rRenderContext=..., rRect=...) at /opt/libreoffice/co-22.05/sw/source/core/crsr/crsrsh.cxx:1428

mpAlphaVDev = {m_rInnerRef = empty rtl::Reference}, mnOutOffOrigX = 0, mnOutOffLogicX = 0, mnOutOffOrigY = 0, mnOutOffLogicY = 0, mnOutOffX = 0, mnOutOffY = 0, mnOutWidth = 817, mnOutHeight = 21481, mnDPIX = 96, mnDPIY = 96, mnDPIScalePercentage = 100

Seem we have a giant alpha vdev too ...

mmeeks commented 1 year ago

Ok - this one: https://gerrit.libreoffice.org/c/core/+/150117 lok: avoid painting writer windows to a giant virtual-device. [NEW] has a disappointing full invalidation that goes with it but is much faster ...

mmeeks commented 1 year ago

@caolanm is kindly taking over getting this into 23.05 - and ideally also distro/collabora/co-22.05