Bug 114392 - MacOS: Increased CPU usage while typing
Summary: MacOS: Increased CPU usage while typing
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
5.4.0.3 release
Hardware: All macOS (All)
: medium minor
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: perf
Depends on:
Blocks: MacOS-Performance
  Show dependency treegraph
 
Reported: 2017-12-10 19:51 UTC by Telesto
Modified: 2024-07-05 23:08 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Telesto 2017-12-10 19:51:16 UTC
Description:
Probably an implementation detail, but the CPU time spend for screen rendering while typing has increased (not noticeable in daily usage)  Likely doubled, but not sure (hard the measure). It seems to spend more time with alpha bitmaps handling.

Not sure what the impact is for a high res screen..

Steps to Reproduce:
1. Launch LibreOffice 5.4 or 6b2 or 6.1 alpha with Instrument using the time profile
2. Start typing 4 rows of text.
3. Create also a time profile using Libreoffice 5.3.7.2
4. Compare both of the time profiles
* the 6.0 profile will be spiky/ 5.3. flatter..
* . Drill Down to SwRootFrame::PaintSwFrame(OutputDevice&, SwRect const&, SwPrintData const*) const en compare the time spend while there. 
5. Compare the results with LibreOffice 5.3.7.2


Actual Results:  
It looks like more time is spend rendering 

Expected Results:
The big question.. 


Reproducible: Always


User Profile Reset: No



Additional Info:
Found in
Version: 6.1.0.0.alpha0+
Build ID: d46dc8e547810208287aab77f0313f1971901464
CPU threads: 4; OS: Mac OS X 10.12.6; UI render: default; 
TinderBox: MacOSX-x86_64@49-TDF, Branch:master, Time: 2017-12-08_10:35:46
Locale: nl-NL (nl_NL.UTF-8); Calc: group threaded

and in 
5.4.0.3

but not in 
5.3.7.2

A possible candidate:
https://cgit.freedesktop.org/libreoffice/core/commit/?h=libreoffice-5-4&id=b5699cd01b6a52906880c107bac6f3802ea7353d


User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8
Comment 1 Alex Thurgood 2017-12-13 08:49:51 UTC
Confirming with my master build 6.0alpha1.

The main lag seems to appear for me in the handling in bitmap.cxx, line 945:

    Bitmap aBmp(GetBitmap(aDstRect.TopLeft(), aDstRect.GetSize()));

which is called by function :

void OutputDevice::DrawDeviceAlphaBitmapSlowPath(const Bitmap& rBitmap, const AlphaMask& rAlpha, tools::Rectangle aDstRect, tools::Rectangle aBmpRect, Size& aOutSize, Point& aOutPoint)
Comment 2 QA Administrators 2019-03-03 03:41:29 UTC Comment hidden (obsolete)
Comment 3 QA Administrators 2021-03-03 03:52:53 UTC Comment hidden (obsolete)
Comment 4 Luboš Luňák 2021-11-18 14:09:03 UTC
Please try this with a developer build from https://dev-builds.libreoffice.org/daily/master/ [*]. Check with option Tools->Options->View->Use Skia for all rendering both enabled and disabled, and when enabled with both Force Skia software rendering enabled and disabled.

And is this a duplicate of bug #120727?

[*] Today's build may still have some rendering problems in dialogs, so tomorrow's should be better, but even today's should be usable for testing this bug.
Comment 5 Telesto 2022-12-26 12:32:53 UTC
Well unsure what was about exactly. 

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 8635c9aa8c6f1078a9e220076d5a08daf30077e8
CPU threads: 8; OS: Mac OS X 12.3.1; UI render: Skia/Metal; VCL: osx
Locale: nl-NL (nl_NL.UTF-8); UI: en-US
Calc: threaded

This is still relatively expensive
                  sw::DocumentTimerManager::DoIdleJobs(Timer*)
                   SwViewShell::LayoutIdle()
                    SwLayIdle::SwLayIdle(SwRootFrame*, SwViewShellImp*)
                     SwViewShell::ImplUnlockPaint(bool)
                      VirtualDevice::ImplSetOutputSizePixel(Size const&, bool, unsigned char*)
                       VirtualDevice::InnerImplSetOutputSizePixel(Size const&, bool, unsigned char*)
                        AquaSalVirtualDevice::SetSize(long, long)
                         CGLayerCreateWithContext
                          CGContextDelegateCreateForContext
                           ripc_GetLayer
                            RIPLayerCreate
                             _malloc_zone_calloc
                            ripc_Initialize
                            pthread_mutex_init
Comment 6 Telesto 2022-12-26 12:41:12 UTC
Incomplete stack
                  sw::DocumentTimerManager::DoIdleJobs(Timer*)
                   SwViewShell::LayoutIdle()
                    SwLayIdle::SwLayIdle(SwRootFrame*, SwViewShellImp*)
                     SwViewShell::ImplUnlockPaint(bool)
                      VirtualDevice::ImplSetOutputSizePixel(Size const&, bool, unsigned char*)
                       VirtualDevice::InnerImplSetOutputSizePixel(Size const&, bool, unsigned char*)
                        AquaSalVirtualDevice::SetSize(long, long)
                         CGLayerCreateWithContext
                          CGContextDelegateCreateForContext
                           ripc_GetLayer
                            RIPLayerCreate
                             _malloc_zone_calloc
                              szone_malloc_should_clear
                               large_malloc
                                _platform_bzero$VARIANT$Haswell


See also
https://www.pybloggers.com/2016/12/debugging-your-operating-system-a-lesson-in-memory-allocation/

Starting from
The key note here is that we can clearly see that we’re spending the bulk of our time in _platform_bzero$VARIANT$Haswell. This method is used to zero buffers. This means that macOS is zeroing out the buffers. Why?
Comment 7 Telesto 2023-01-03 09:09:57 UTC
@Patrick
Xcode instruments shows that cpu time being spend in _platform_bzero$VARIANT$Haswell in a regular fashion while typing. The link in comment 6 suggests this not being optimal. The question: is this worth investigating or should the bug be closed as NOTABUG or WONTFIX