Skip to content

Write a view DataString with one block copy - #4

Open
quinnj wants to merge 1 commit into
mainfrom
claude/write-views-in-one-copy
Open

quinnj wants to merge 1 commit into
mainfrom
claude/write-views-in-one-copy

Conversation

@quinnj

@quinnj quinnj commented Oct 16, 2026

Copy link
Copy Markdown
Member

write(io, ::DataString) wrote one byte per call. A view's content is one contiguous run of its retained buffer, so this writes it with a single unsafe_write. Inline strings (12 bytes or fewer) keep the byte loop, which measured the same as a block write. print, string interpolation, and string all go through this method.

Writing 10,000 view strings of 13-40 bytes to an IOBuffer (Chairmarks, Julia 1.12.6, same process, interleaved, three rounds): 1.10-1.31 ms before, 0.23-0.27 ms after (about 4.5x). With an IOStream, each per-byte write also takes the stream lock, so the gap is larger there.

Verification:

  • New test writes empty, inline, 12-byte, and view strings, including a view at a nonzero offset in a shared column buffer, and checks the byte count and content.
  • Full Pkg.test() passes on Julia 1.10.11 and 1.12.6.

🤖 Generated with Claude Code

`write(io, ::DataString)` copied one byte per call. A view's content is
one contiguous run of its retained buffer, so write it with a single
`unsafe_write`. `print`, interpolation, and `string` all go through this
method; writing 13-40 byte strings to an IOBuffer is about 4.5x faster.
Inline strings keep the byte loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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