pyapp-kit / superqt

Missing widgets and components for Qt-python
https://pyapp-kit.github.io/superqt/
BSD 3-Clause "New" or "Revised" License
210 stars 38 forks source link

Prevent computing full document content highlight per block and only compute current block content for performance #246

Closed dalthviz closed 6 months ago

dalthviz commented 6 months ago

Related with https://github.com/napari/napari/issues/6845

Current code computes the full document highlight for each document block/paragraph causing freezes as soon the document content starts to get a little bit long. To reproduce, you can run the examples/code_highlight.py, copy and paste the widget text content multiple times (selecting the full content to do a new paste increases the chance to stumble with a freeze in a shorter amount of time). So something like:

highlight

This PR tries to prevent/improve the situation by only computing the current block content/text highlight data (not sure if there is a better approach so happy to give a check to any other ideas!). Doing a similar check with the example content copy and paste operations with the changes in this PR:

highlight_perf

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 87.07%. Comparing base (0ec5cd3) to head (f785fe3).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #246 +/- ## ========================================== - Coverage 87.12% 87.07% -0.06% ========================================== Files 46 46 Lines 3403 3397 -6 ========================================== - Hits 2965 2958 -7 - Misses 438 439 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tlambert03 commented 6 months ago

@Czaki, since this is your object, would appreciate your review

Czaki commented 6 months ago

This change provides a significant performance boost and I do not see downsides of these changes.

Test failures look unrelated.