-
-
Notifications
You must be signed in to change notification settings - Fork 703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce FixedAppender #8789
base: master
Are you sure you want to change the base?
Introduce FixedAppender #8789
Conversation
Thanks for your pull request and interest in making D better, @John-Colvin! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8789" |
29bd96d
to
d08bba3
Compare
d08bba3
to
7d70346
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, will wait for others to review though.
I think that test failure might be legit, looking in to it now. Also considering a different approach using a prefix allocator... let's see... |
@deadalnix suggests "inPlaceAppender" as a name, idk... better than "fixed". |
This provides an appender that doesn't hold its data in an indirection which needs allocating, the lack of which reduces overhead substantially for situations where the amount of actual work done with the appender is small (e.g. the number of elements appended is small). For maybe 95% of use-cases, the user does not want to pass an appender around by value, in fact it's hard to see why that would be desirable, so we take advantage of that and create a non-copyable
FixedAppender
which can store all its data "in-place".I intend to spread its use around Phobos initially, for testing the interface, then expose it publicly later (so we can defer arguing about the name too much for now plz).
A separate attempt was made to improve
Appender
by deferring the allocation to the first copy using copy-constructors, but this did not go well due to problems with inout, const etc. but also that had the consequence of causing an allocation in a somewhat unexpected - and different - place. Hence, it was abandoned for now in favour of this.The following is a diff to std.json, which when applied with the test code below it & a big json file (taken from https://github.com/json-iterator/test-data/blob/master/large-file.json) led to a reduction in runtime from 400-430 ms to around 350 ± 8 ms
test_json.d