-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Speed up toXContent Collection Serialization in some Spots #78742
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
original-brownbear
merged 5 commits into
elastic:master
from
original-brownbear:faster-serialize-collections
Oct 6, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6f8507e
Speed up toXContent Collection Serialization in some Spots
original-brownbear ef34e75
nicer
original-brownbear 219f9f7
fix
original-brownbear 73e94bc
Merge remote-tracking branch 'elastic/master' into faster-serialize-c…
original-brownbear 0552604
null checks
original-brownbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,10 @@ | |
import java.util.Arrays; | ||
import java.util.Base64; | ||
import java.util.Calendar; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
import java.util.EnumSet; | ||
import java.util.GregorianCalendar; | ||
import java.util.HashMap; | ||
import java.util.IdentityHashMap; | ||
|
@@ -921,6 +923,58 @@ private XContentBuilder value(ToXContent value, ToXContent.Params params) throws | |
// Maps & Iterable | ||
////////////////////////////////// | ||
|
||
public XContentBuilder stringListField(String name, Collection<String> values) throws IOException { | ||
field(name); | ||
if (values == null) { | ||
return nullValue(); | ||
} | ||
startArray(); | ||
for (String value : values) { | ||
value(value); | ||
} | ||
endArray(); | ||
return this; | ||
} | ||
|
||
public XContentBuilder xContentList(String name, Collection<? extends ToXContent> values) throws IOException { | ||
field(name); | ||
if (values == null) { | ||
return nullValue(); | ||
} | ||
startArray(); | ||
for (ToXContent value : values) { | ||
value(value); | ||
} | ||
endArray(); | ||
return this; | ||
} | ||
|
||
public XContentBuilder xContentList(String name, ToXContent... values) throws IOException { | ||
field(name); | ||
if (values == null) { | ||
return nullValue(); | ||
} | ||
startArray(); | ||
for (ToXContent value : values) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe check for non null array here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh right TIL, I I always figured I'd get |
||
value(value); | ||
} | ||
endArray(); | ||
return this; | ||
} | ||
|
||
public XContentBuilder enumSet(String name, EnumSet<?> values) throws IOException { | ||
field(name); | ||
if (values == null) { | ||
return nullValue(); | ||
} | ||
startArray(); | ||
for (Enum<?> value : values) { | ||
value(value); | ||
} | ||
endArray(); | ||
return this; | ||
} | ||
|
||
public XContentBuilder field(String name, Map<String, Object> values) throws IOException { | ||
return field(name).map(values); | ||
} | ||
|
@@ -929,6 +983,32 @@ public XContentBuilder map(Map<String, ?> values) throws IOException { | |
return map(values, true, true); | ||
} | ||
|
||
public XContentBuilder stringStringMap(String name, Map<String, String> values) throws IOException { | ||
field(name); | ||
if (values == null) { | ||
return nullValue(); | ||
} | ||
startObject(); | ||
for (Map.Entry<String, String> value : values.entrySet()) { | ||
field(value.getKey()); | ||
value(value.getValue()); | ||
} | ||
return endObject(); | ||
} | ||
|
||
public XContentBuilder xContentValuesMap(String name, Map<String, ? extends ToXContent> values) throws IOException { | ||
field(name); | ||
if (values == null) { | ||
return nullValue(); | ||
} | ||
startObject(); | ||
for (Map.Entry<String, ? extends ToXContent> value : values.entrySet()) { | ||
field(value.getKey()); | ||
value(value.getValue()); | ||
} | ||
return endObject(); | ||
} | ||
|
||
/** writes a map without the start object and end object headers */ | ||
public XContentBuilder mapContents(Map<String, ?> values) throws IOException { | ||
return map(values, true, false); | ||
|
@@ -1026,6 +1106,11 @@ public XContentBuilder percentageField(String rawFieldName, String readableField | |
return this; | ||
} | ||
|
||
public XContentBuilder field(String name, Enum<?> value) throws IOException { | ||
field(name); | ||
return value(value == null ? null : value.toString()); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////// | ||
// Raw fields | ||
////////////////////////////////// | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: maybe just
array(String name, Collection<String> values)
? Same remark for the other new methods.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.
Can't do that unfortunately because we have:
which collides with it. Same with the other cases, these super generic
?
orObject
type methods collide with everything.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.
Oh right, I did not see this one. Let's keep like it is then.