dankamongmen / notcurses

blingful character graphics/TUI library. definitely not curses.
https://nick-black.com/dankwiki/index.php/Notcurses
Other
3.43k stars 113 forks source link

Speed up startup that got slow since #2696 #2698

Closed Spritetm closed 1 year ago

Spritetm commented 1 year ago

2696 added a bunch of numeric fields to the input automaton, greatly slowing down startup times of any notcurses program. This is mostly because numeric fields aren't handled optimally in the automaton: on creation, a lot of links are created from one trie node via the digits 0-9 to another one. When appending more patterns, the automaton creation logic takes each of these digit links as an individual path that should be followed recursively, which greatly increases processing time. This patch makes the logic recognize this and skips following a path if it is the same as the path followed before.

To illustrate, the times on my laptop to run notcurses-info are as following: Master, before #2696: 0m0.031s
Master, after #2696: 0m1.001s
After this patch: 0m0.034s

Closes #2697

Spritetm commented 1 year ago

Sorry, hold this for a sec, I think I found a bug...

Spritetm commented 1 year ago

Okay, fixed now. I broke my own code to get the effective text somehow :X Along with the fix is an addition to ncurses-input to show the effective text if it differs from the key id/utf8; this should make bugs that break #2696 easier to spot.