-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Faster json parsing #1980
Faster json parsing #1980
Conversation
Signed-off-by: amannocci <adrien.mannocci@gmail.com>
Signed-off-by: amannocci <adrien.mannocci@gmail.com>
Signed-off-by: amannocci <adrien.mannocci@gmail.com>
Signed-off-by: amannocci <adrien.mannocci@gmail.com>
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
Maybe we can directly write into a buffer ? public static Buffer encodeToBuffer(Object obj) throws EncodeException {
try {
Buffer buf = Buffer.buffer();
mapper.writeValue(new ByteBufOutputStream(buf.getByteBuf()), obj);
return buf;
} catch (Exception e) {
throw new EncodeException("Failed to encode as JSON: " + e.getMessage());
}
} We need also to remove the method decodeValue based on InputStream. public static <T> T decodeValue(InputStream stream, Class<T> clazz) throws DecodeException { I will attempt to do a little jmh benchmark to confirm performance improvement before merge. |
We can add a method with TypeReference too ? public static <T> T decodeValue(Buffer buf, TypeReference<T> type) throws DecodeException |
…ence Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
@amannocci your comments have been added to the PR |
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.
a few doc changes before proceeding
@@ -69,6 +72,16 @@ public static String encode(Object obj) throws EncodeException { | |||
} | |||
} | |||
|
|||
public static Buffer encodeToBuffer(Object obj) throws EncodeException { |
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.
missing doc
@@ -93,6 +106,22 @@ public static String encodePrettily(Object obj) throws EncodeException { | |||
} | |||
} | |||
|
|||
public static <T> T decodeValue(Buffer buf, TypeReference<T> type) throws DecodeException { |
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.
missing doc
} | ||
} | ||
|
||
public static <T> T decodeValue(Buffer buf, Class<T> clazz) throws DecodeException { |
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.
missing doc
@@ -545,6 +554,15 @@ public String encode() { | |||
} | |||
|
|||
/** | |||
* Encode this JSON object as a string. | |||
* | |||
* @return the string encoding. |
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.
the encoded string, string encoding means something else
@@ -764,6 +773,15 @@ public String encodePrettily() { | |||
} | |||
|
|||
/** | |||
* Encode this JSON object as a string. | |||
* | |||
* @return the string encoding. |
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.
the encoded string
Signed-off-by: Paulo Lopes <pmlopes@gmail.com>
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.
I've had a look at @amannocci benchmarks at https://github.com/amannocci/vertx-bench-json/blob/master/src/main/java/io/vertx/bench/JsonBenchmark.java but I have concerns as it is difficult to evaluate wether Hotspot is doing DCE / partial constant propagation, etc.
@amannocci your benchmark methods should return some value, here the JSON object. See my article at http://www.oracle.com/technetwork/articles/java/architect-benchmarking-2266277.html
To be clear: I do think your changes boost performance, but I'd like a more rigorous evaluation in your benchmarks to know exactly by how much 😉 (and maybe you will just end up with the same figures) |
I'm agree with you @jponge. I will try to improve the actual benchmark to be sure. |
I have done some modifications on my benchmark as proposed by @jponge .
Let me know if I'm wrong. |
LGTM 👍 |
LGTM |
can you rebase the branch so it can be merged ? thanks |
it can be merged, why do we need to rebase? |
I can see "This branch cannot be rebased due to conflicts" in github |
@vietj "Merging can be performed automatically" 😉 |
the UI was not really clear |
Implement a
toBuffer
to all json objects.This PR extends #1976 and fixes the ip-check that was resolved using the github web interface which does not sign off commits.