Skip to content

perf: obs-graphics: lzw_decode (output stack) is 18 % slower than the C #2504

Closed

Description

@vpacher

What

The Rust LZW decoder of #2466 (obs_graphics::lzw, swapped in the hybrid libobs since #2471) is slower than the C through lzw_decode, the output stack:

port_comparison, M1 Max, one 1920×1080 frame Rust C
lzw_decode_map (full-width frame) 10.41 ms 10.16 ms (+2.5 %)
lzw_decode until the end of the data (output stack) 10.50 ms 8.86 ms (+18.5 %)

#2466 measured only lzw_decode_map. libnsgif uses lzw_decode for every interlaced or clipped frame (the complex path of the frame decode). PR #2503 (#2501) found the gap: the interlaced 1080p frame decode is 17 % slower, and the LZW stack decode is most of that.

Cause

From a profile of the Rust stack decode:

  • Decoder::write matches on the writer (stack or colour map) for every value; the C passes its writer as a separate inline function.
  • Every value reads its table entry and writes the stack through a bounds-checked index, although codes are at most 12 bits and stack positions below 4096.
  • Input::read_code is about a quarter of the time: its fast path reads three bytes with three bounds-checked reads.

Plan

One PR: a port_comparison bench for lzw_decode first (lzw/decode_stack_1080p), then the fix in obs-graphics, with Tier 1 (render::lzw) and Tier 3 (render::lzw_parity) unchanged as the proof that results do not change.

Activity

  1. vpacher commented on Oct 26, 2026

    @vpacher
    MemberAuthor

    Claiming: #2504

    Plan as in the description: one PR, the lzw_decode bench first, then the fix; Tier 1 and Tier 3 unchanged.

  2. self-assigned this
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions