Bug 423680

Summary: Very high CPU load when entering a number in C++ syntax
Product: [Frameworks and Libraries] frameworks-syntax-highlighting Reporter: Andrey Kozlovskiy <akozlovskiy119>
Component: syntaxAssignee: Nibaldo G. <nibgonz>
Status: RESOLVED FIXED    
Severity: normal CC: nibgonz, walter.von.entferndt
Priority: NOR    
Version First Reported In: 5.71.0   
Target Milestone: ---   
Platform: Neon   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 5.73.0
Sentry Crash Report:
Attachments: Kwrite: hold '1' key CPU load - Normal vs C++

Description Andrey Kozlovskiy 2020-06-29 22:42:57 UTC
Created attachment 129778 [details]
Kwrite: hold '1' key CPU load - Normal vs C++

When I hold a number key to enter some long number in C++, kwrite/kate starts to lag and one of the CPU cores immediately loads up to 100%.

Problem is specific to C++/ISO C++ syntax. C, Rust, Java, JavaScript, for example, are not affected.

See attached video for example.
Comment 1 Nibaldo G. 2020-07-03 03:13:50 UTC
In the ISO C++ highlighter (isocpp.xml), to detect a number, many context switches occur (there are 4-5 context switches) and there are many RegExpr rules; since suffixes, number types and invalid characters are highlighted. This may explain the high CPU usage.
Comment 2 Nibaldo G. 2020-07-03 07:32:43 UTC
I did tests on "isocpp.xml": in the "Number" context there is a RegExpr rule with a very large regular expression to detect float numbers. This is responsible for slowing down aand using high CPU by writing numbers in C++/ISO C++
Comment 3 Bug Janitor Service 2020-07-05 09:16:30 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/syntax-highlighting/-/merge_requests/10