Skip to content

Optimized #consumeAsync() and couple other small things #452

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

Merged
merged 5 commits into from
Dec 27, 2017

Conversation

lutovich
Copy link
Contributor

No description provided.

`PullAllResponseHandler` keeps all result records in a queue. It used
to always allocate this queue even for queries that return no results.
This resulted in unnecessary garbage generation for write-only queries
that return nothing.

This commit makes `PullAllResponseHandler` start with an empty
unmodifiable queue and allocate a real one when first record arrives.
String values from `ServerVersion#toString()` and
`BoltServerAddress#toString()` are used to create result summary for
every query. Thus it is reasonable to memorize them and not recompute
every time.
`LinkedHashMap` has default load factor of 0.75. It is often not enough
to specify desired initial capacity in order for the map to not resize.

This commit adds a helper method to create `LinkedHashMap` that will
not resize.
Each message consists of one or more chunks. Each chunk is prefixed
with a fixed-size header which contains two bytes - chunk body size.
Messages are separated by a "message boundary" which is a two byte
message "00".

Code used to keep message boundary and empty chunk header as shared
`ByteBuf` constants. These buffers were duplicated (no content copying
involved) for every operation. This resulted in creation of multiple
lightweight but unnecessary wrapper objects.

This commit makes code write both message boundary and empty temporary
chunk header directly into IO buffers and removes the need to duplicate
shared buffers. So no temporary objects are created.
Previously it was implemented using `#forEachAsync()` and a no-op
consumer. This resulted in every record being added to the queue of
incoming records, then wrapped in a `CompletableFuture` and only then
thrown away. So it did a lot more work than needed.

This commit optimizes `#consumeAsync()` and `StatementResult#consume()`
that builds on top of it. Now all incoming values will not be
transformed into records and will be dropped right away. So no queueing
and `CompletableFuture`s will be involved.
@lutovich lutovich requested a review from ali-ince December 22, 2017 15:21
Copy link
Contributor

@ali-ince ali-ince left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ali-ince ali-ince merged commit 8120bf7 into neo4j:1.5 Dec 27, 2017
@lutovich lutovich deleted the 1.5-couple-small-optimizations branch December 27, 2017 11:23
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.

2 participants