Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

True colour to xterm256 conversion: significant speed up #432

Closed
wants to merge 1 commit into from

Commits on May 30, 2016

  1. True colour to xterm256 conversion: significant speed up

    Speed:
    In a hot loop, where the old code has its ~2K pre-calculated data
    already cached, this new code is x40-x50 faster (gcc/clang) with
    arbitrary RGB values, and ~x3 faster with RGB values which have an
    exact xterm256 colour representation (e.g. #5f87ff).
    
    When used sparsely, or otherwise when the old code doesn't have the
    data cached, the new code is likely to be at least another order of
    magnitude faster, as it does not use pre-calculated data (technically,
    it uses less than 20 constants).
    
    Further 50% speed-up is possible with 256 bytes of pre-calculated date,
    or 100% (x2 speed up) with 1K of pre-calculated data.
    
    Compatibility:
    This code returns identical values as the old code for the same inputs.
    
    However, the old code is implicitly rounding down from the middle. For
    instance, for RGB of (13, 13, 13) which is exactly between the
    potential return values 232 (8, 8, 8) and 233 (18, 18, 18), it returns
    232. It does the same with colour values at 16..231 .
    
    While there's no right or wrong in this case between rounding up/down,
    the new code also supports the more conventional paradigm of rounding
    up from the middle. To enable it, set `LC` (legacy compatibility) to 0.
    avih committed May 30, 2016
    Copy the full SHA
    05e82d6 View commit details
    Browse the repository at this point in the history