Page MenuHomeFreeBSD

stdio: *memstream: grow the buffer by 1.5x on write
AcceptedPublic

Authored by kevans on Fri, May 29, 11:43 PM.
Tags
None
Referenced Files
F159371000: D57355.id178973.diff
Sat, Jun 13, 9:56 AM
Unknown Object (File)
Fri, Jun 12, 11:52 PM
Unknown Object (File)
Fri, Jun 12, 7:18 PM
Unknown Object (File)
Wed, Jun 10, 12:35 PM
Unknown Object (File)
Wed, Jun 10, 12:24 PM
Unknown Object (File)
Wed, Jun 10, 12:11 PM
Unknown Object (File)
Mon, Jun 8, 3:50 PM
Unknown Object (File)
Mon, Jun 8, 3:39 PM
Subscribers

Details

Reviewers
jhb
des
Group Reviewers
Klara
Summary

This improves performance by reducing the number of allocations as we
write into the memstream, both in the fully buffered case with larger
memstreams and also more trivially in the line- and un-buffered case as
they flush back to the underlying buffer more often.

The inspiration for this was taken from Apple's implementation in
https://github.com/apple-oss-distributions/libc, but expanded to include
wmemstream for consistency. I've added a test for the bug that I hit in
libder that caused me to notice this in the first place, and fixed that
bug in this version.

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 73691
Build 70574: arc lint + arc unit

Event Timeline

des requested changes to this revision.Wed, Jun 3, 1:07 PM
des added a subscriber: des.
des added inline comments.
lib/libc/stdio/open_memstream.c
35
70
75

you can replace this entire thing with just ckd_add(&growsize, ms->size, ms->size / 2)

lib/libc/tests/stdio/open_memstream2_test.c
191

I'd prefer including a description if it's not too much trouble

223–225
This revision now requires changes to proceed.Wed, Jun 3, 1:07 PM
kevans marked 3 inline comments as done.

Review feedback: use ckd_add() and add test descriptions

des added inline comments.
lib/libc/stdio/open_memstream.c
35

I don't think you actually need <stdbool.h> here

This revision is now accepted and ready to land.Fri, Jun 5, 7:30 AM