Skip to content

Conversation

@mfontani
Copy link
Owner

@mfontani mfontani commented Jan 9, 2025

just_strip_it: rearrange to speed things up

  • use a few "register" variables for likely hot spots
  • stop tracking the sgrs[] as we mostly don't care about previous values (i.e. was there a "1;"?) if we're stripping ANSI: all we care is really about finding the ending "m" and verifying (but we could drop that) that each number in the ";" sequence is 0-255.
  • rearrange the switch() into a series of if/else roughly based on how prevalent it ought to be in a common ANSI text input.

Feeding this my usual 50M-100M-1G-1.5G ANSI-laden files, both "normal" (from an ANSI telnet-based MUD) and "pernicious" where basically every character or so is a different color, this speeds things up in the region of 2-7% depending.
Files without ANSI don't get any particular speed-up.

- use a few "register" variables for likely hot spots
- stop tracking the sgrs[] as we mostly don't care about previous values
  (i.e. was there a "1;"?) if we're stripping ANSI: all we care is
  really about finding the ending "m" and _verifying_ (but we could drop
  that) that each number in the ";" sequence is 0-255.
- rearrange the switch() into a series of if/else roughly based on how
  prevalent it ought to be in a common ANSI text input.

Feeding this my usual 50M-100M-1G-1.5G ANSI-laden files, both "normal"
(from an ANSI telnet-based MUD) and "pernicious" where basically every
character or so is a different color, this speeds things up in the
region of 2-7% depending.
Files without ANSI don't get any particular speed-up.
@mfontani mfontani merged commit 3f244af into master Jan 9, 2025
4 checks passed
@mfontani mfontani deleted the mf/202501_optimize_strip branch January 9, 2025 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants