Skip to content

PERF: short-circuit fragmentation check in BlockManager.insert#64756

Open
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel:perf-57641
Open

PERF: short-circuit fragmentation check in BlockManager.insert#64756
jbrockmendel wants to merge 1 commit intopandas-dev:mainfrom
jbrockmendel:perf-57641

Conversation

@jbrockmendel
Copy link
Member

Summary

  • Add a len(self.blocks) > 100 guard in BlockManager.insert to skip the O(n) block iteration and get_option call when the block count is small

closes #57641

Benchmarks

Benchmark Before After Speedup
InsertColumns.time_insert 7.37 ms 4.47 ms 39%
InsertColumns.time_insert_middle 7.42 ms 4.42 ms 40%
InsertColumns.time_assign_with_setitem 5.00 ms 2.20 ms 56%

Test plan

  • Existing tests pass (test_insert.py, test_block_internals.py)

🤖 Generated with Claude Code

Add a len(self.blocks) > 100 guard before the O(n) block iteration
and get_option call in insert(), since the non-extension block count
can never exceed the total block count.

closes pandas-dev#57641

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jbrockmendel jbrockmendel added the Performance Memory or execution speed performance label Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Performance Memory or execution speed performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential regression induced by PR #56921

1 participant