Skip to content

fix: Slice packed text through its selection layer - #224

Open
SamuelSchlesinger wants to merge 2 commits into
DataHaskell:mainfrom
SamuelSchlesinger:fix/slice-packed-text
Open

fix: Slice packed text through its selection layer#224
SamuelSchlesinger wants to merge 2 commits into
DataHaskell:mainfrom
SamuelSchlesinger:fix/slice-packed-text

Conversation

@SamuelSchlesinger

Copy link
Copy Markdown

sliceColumn on a PackedText column materialized the whole column to boxed Text first, so a ten-row slice cost the whole frame and came back in a different representation. Gather the slice directly and keep it packed.

Also adds the bounds check the boxed/unboxed arms already have — packedGather would otherwise decode an overrun as empty strings.

takeColumn slices a packed payload through packedTake, which caps the
selection and shares the byte buffer. sliceColumn instead routes through
materializePacked, decoding every row of the column to Text before
taking the handful of rows asked for, so the cost of a small slice
scales with the frame. drop, dropLast, range and takeLast all go through
it, and every text column read from CSV is packed.

The third case pins the bounds contract the other two representations
already keep: a slice running past the end is rejected, not decoded.
sliceColumn decoded the whole column to a boxed Text vector before
taking the requested rows, so a small slice cost O(rows) rather than
O(slice). Reuse packedGather, which shares the byte buffer, matching
what takeColumn already does with packedTake.

packedGather decodes an out-of-range index as the empty string where the
boxed and unboxed arms reject the slice, so the bounds are checked first
and the three representations agree.

On a 300k-row CSV with two text columns, range (10, 20) drops from
16.2ms to 1us and drop 10 from 27.6ms to 2us.
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