-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Speed up synthetic source #87882
Speed up synthetic source #87882
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,14 +82,24 @@ public boolean reordersFieldValues() { | |
@Override | ||
public Leaf leaf(LeafReader reader) throws IOException { | ||
SyntheticFieldLoader.Leaf leaf = loader.leaf(reader); | ||
if (leaf.empty()) { | ||
return new Leaf() { | ||
@Override | ||
public BytesReference source(FieldsVisitor fieldsVisitor, int docId) throws IOException { | ||
// TODO accept a requested xcontent type | ||
try (XContentBuilder b = new XContentBuilder(JsonXContent.jsonXContent, new ByteArrayOutputStream())) { | ||
return BytesReference.bytes(b.startObject().endObject()); | ||
} | ||
} | ||
}; | ||
} | ||
return new Leaf() { | ||
@Override | ||
public BytesReference source(FieldsVisitor fieldsVisitor, int docId) throws IOException { | ||
// TODO accept a requested xcontent type | ||
try (XContentBuilder b = new XContentBuilder(JsonXContent.jsonXContent, new ByteArrayOutputStream())) { | ||
leaf.advanceToDoc(docId); | ||
if (leaf.hasValue()) { | ||
leaf.load(b); | ||
if (leaf.advanceToDoc(docId)) { | ||
leaf.write(b); | ||
} else { | ||
b.startObject().endObject(); | ||
} | ||
|
@@ -104,20 +114,19 @@ public BytesReference source(FieldsVisitor fieldsVisitor, int docId) throws IOEx | |
* Load a field for {@link Synthetic}. | ||
*/ | ||
interface SyntheticFieldLoader { | ||
/** | ||
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. Still worth having some javadoc on this I think? 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. Not sure what I did there. |
||
* Load no values. | ||
*/ | ||
SyntheticFieldLoader NOTHING = r -> new Leaf() { | ||
@Override | ||
public void advanceToDoc(int docId) throws IOException {} | ||
public boolean empty() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean hasValue() { | ||
public boolean advanceToDoc(int docId) throws IOException { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void load(XContentBuilder b) throws IOException {} | ||
public void write(XContentBuilder b) throws IOException {} | ||
}; | ||
|
||
/** | ||
|
@@ -130,19 +139,19 @@ public void load(XContentBuilder b) throws IOException {} | |
*/ | ||
interface Leaf { | ||
/** | ||
* Position the loader at a document. | ||
* Is this entirely empty? | ||
*/ | ||
void advanceToDoc(int docId) throws IOException; | ||
boolean empty(); | ||
|
||
/** | ||
* Is there a value for this field in this document? | ||
* Position the loader at a document. | ||
*/ | ||
boolean hasValue(); | ||
boolean advanceToDoc(int docId) throws IOException; | ||
|
||
/** | ||
* Load values for this document. | ||
* Write values for this document. | ||
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. ❤️ |
||
*/ | ||
void load(XContentBuilder b) throws IOException; | ||
void write(XContentBuilder b) throws IOException; | ||
} | ||
} | ||
|
||
|
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.
Given this has no state I wonder if it's worth having it as a final instance on Leaf?
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.
👍