BartMiki commented on issue #12912:
URL: https://github.com/apache/druid/issues/12912#issuecomment-1221266813
Regarding the performance, I think there are no big differences. I made
these test for both:
Old implementation:
```java
public void testOldCode() throws JsonProcessingException {
ObjectMapper mapper = new DefaultObjectMapper();
Event event = getEvent();
for (int i = 0; i < LOOP_COUNT; i++) {
ImmutableMap.Builder<String, Object> resultBuilder =
ImmutableMap.<String, Object>builder().putAll(event.toMap());
if (CLUSTER_NAME != null) {
resultBuilder.put("clusterName", CLUSTER_NAME);
}
Map<String, Object> result = resultBuilder.build();
String resultJson = mapper.writeValueAsString(result);
}
}
```
New implementation:
```java
public void testMyCode() throws JsonProcessingException
{
ObjectMapper mapper = new DefaultObjectMapper();
Event event = getEvent();
for (int i = 0; i < LOOP_COUNT; i++) {
EventToJsonSerializer serializer =
EventToJsonSerializer.of(mapper).withProperty("clusterName", CLUSTER_NAME);
String actual = serializer.serialize(event);
}
}
```
I set up LOOP_COUNT to 100K. The results differ between the runs slightly,
but these are the results (from IntelliJ):

Sometimes my code is slower:

I think that 100K is enough for the JIT to warm up. I guess the performance
is comparable and it shouldn't be an issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]