Skip to content

Codeflash/optimize#1

Closed
misrasaurabh1 wants to merge 11 commits intomainfrom
codeflash/optimize
Closed

Codeflash/optimize#1
misrasaurabh1 wants to merge 11 commits intomainfrom
codeflash/optimize

Conversation

@misrasaurabh1
Copy link
Copy Markdown

Fixes # .

Changes proposed in this pull request:

codeflash-ai and others added 11 commits April 4, 2026 07:55
Replace per-element append to 3 separate lists with per-channel list
comprehensions. Reduces self-time by ~80% by avoiding 768+ individual
append calls per invocation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Inline the vertex computation, eliminating nested helper functions
(_apply_rotation, _compute_polygon_vertex, _get_angles). Simplify
the rotation formula since start_point is always [radius, 0], reducing
from 4 trig calls to 2 per vertex. Cache math functions as locals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Specialize for the common cases (both tuples, one scalar) to avoid
unnecessary tuple wrapping and generator overhead per call.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Precompute normalized coordinate arrays to avoid repeated division
in tight loops. Replace slice assignment with list.extend for lower
per-iteration overhead. Cache table.extend as local variable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace functools.reduce(operator.add, ...) with sum() in equalize
- Replace functools.reduce(lambda a,b: a+b, ...) with sum() in Kernel
- Replace per-element loop in solarize with list comprehension
- Replace sum loop in autocontrast with sum(h) builtin
- Use lut.extend(range(256)) instead of lut.extend(list(range(256)))
- Use min/max in autocontrast LUT building for clarity and slight perf
- Remove unused functools and operator imports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Split the inner loop into two paths to avoid checking border is None
on every pixel. Replace p not in (value, border) with direct
comparisons to avoid tuple creation per pixel.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace nested for loops with generator-based sum() calls inside
list comprehensions. Also use j*j instead of j**2 to avoid pow
overhead. Cache self.h as local in median.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace 2 ** (8 - bits) with 1 << (8 - bits) for faster bitmask
computation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
For the common 3-element (RGB) and 4-element (RGBA) cases, compute
the L1 norm directly instead of using sum(generator). Eliminates
generator/zip overhead for the hot path in floodfill.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace append loop with list comprehension for collecting used
palette colors in _get_optimize.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace extend-in-loop with chain.from_iterable for flattening
nested sequences in Color3DLUT constructor. Separate validation
from flattening for cleaner code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@misrasaurabh1 misrasaurabh1 deleted the codeflash/optimize branch April 6, 2026 22:43
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