You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚡️ Speed up function get_diff_lines_count by 19% in PR #274 (skip-formatting-for-large-diffs)
Here is a **much faster** rewrite. The biggest bottleneck was constructing the entire `diff_lines` list just to count its length. Instead, loop directly through the lines and count matching lines, avoiding extra memory and function call overhead. This also removes the small overhead of the nested function.
### Optimizations made.
- **No internal list allocation:** Now iterating and counting in one pass with no extra list.
- **No inner function call:** Faster, via direct string checks.
- **Short-circuit on empty:** Avoids string indexing on empty lines.
- **Direct char compare for '+', '-':** Faster than using tuple membership or `startswith` with a tuple.
This reduces both runtime **and** memory usage by avoiding unnecessary data structures!
0 commit comments