Skip to content

feat(canvas): new buffer check color data identity#642

Open
slook wants to merge 1 commit into
ceccopierangiolieugenio:mainfrom
slook:canvas-bufferred-new-identity-is
Open

feat(canvas): new buffer check color data identity#642
slook wants to merge 1 commit into
ceccopierangiolieugenio:mainfrom
slook:canvas-bufferred-new-identity-is

Conversation

@slook

@slook slook commented May 30, 2026

Copy link
Copy Markdown
Contributor
  • Changed: Optimization by using == to is in the new buffer push method. Only applicable if doubleBufferNew=True.

The is check is a raw pointer comparison with no module method call, no tuple unpacking, and no attribute access. It eliminates all calls to TTkColor.__eq__() in the hottest loop in the library, in favor of simply checking if the data and colors are the same objects or not.

There doesn't seem to be many or any cases where the objects are different but have the same values, so this optimization doesn't appear to result in extra bytes being written to the terminal unnecessarily.

This is much faster than performing separate equality comparison operations for both the foreground and background color values for each character being pushed in the paint event, especially since it avoids the very slow isinstance() call in the __eq__() method of color.py which was recently added in PR #638 (but even if that regression is fixed by PR #641 , then this would still be a good optimization to make anyway).

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.

1 participant