Skip to content

Count table rows without materializing every field during inspect - #371

Open
OskarEichler wants to merge 1 commit into
ruby:mainfrom
OskarEichler:codex/csv-inspect
Open

Count table rows without materializing every field during inspect#371
OskarEichler wants to merge 1 commit into
ruby:mainfrom
OskarEichler:codex/csv-inspect

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Count non-header rows directly instead of building the full to_a representation merely to read its size. Keep the existing five-row preview and header-inclusive count.

Reproduction

Inspecting a 10,000-row, 20-column table currently creates arrays for every row even though only five rows are displayed.

Verification

24 exact-output checks pass across table sizes, header-row presence and all access modes. In seven local measurements of 20 inspections (10,000 rows x 20 columns), median allocations fell from 405,280 to 5,240; median elapsed time fell from 0.192385s to 0.006012s. These are local microbenchmark results, not production throughput claims.

This isolated patch passes the unchanged upstream suite in both normal and CSV_PARSER_SCANNER_TEST=yes modes: 527 tests / 4,050 assertions in each mode, zero failures/errors. Commands use Ruby 4.0.6 through rbenv (bundle exec ruby run-test.rb). Syntax and git diff --check pass. The combined release-based consumer branch also passes gem build and rake warning:error rdoc.

No tests were added or changed, per the requesting project's explicit no-new-tests policy. Focused checks and measurements live outside this repository. The upstream no-RuboCop policy is respected. Verification was local on macOS/Ruby 4.0.6; the supported OS/Ruby matrix was not run locally. Current main and installed 3.3.6 share base commit 0873ab362d996f12796c3c3e8998b5be657a9b12; no unrelated changes are included.

Breaking changes and limitations

None. Inspection text and encoding behavior remain unchanged. Counting still traverses rows; this removes field materialization, not the row scan.

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