-
Notifications
You must be signed in to change notification settings - Fork 20
Cache field metadata during checking and planning #913
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
Changes from all 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 |
|---|---|---|
|
|
@@ -126,6 +126,7 @@ final class Planner implements InterpretablePlanner { | |
| private final Container container; | ||
| private final Map<Long, Reference> refMap; | ||
| private final Map<Long, Type> typeMap; | ||
| private final Map<String, FieldType> fieldTypes = new HashMap<>(); | ||
| private final InterpretableDecorator[] decorators; | ||
|
|
||
| Planner( | ||
|
|
@@ -249,7 +250,7 @@ Interpretable planSelect(Expr expr) { | |
| FieldType fieldType = null; | ||
| Type opType = typeMap.get(sel.getOperand().getId()); | ||
| if (opType != null && !opType.getMessageType().isEmpty()) { | ||
| FieldType ft = provider.findFieldType(opType.getMessageType(), sel.getField()); | ||
| FieldType ft = findFieldType(opType.getMessageType(), sel.getField()); | ||
| if (ft != null && ft.isSet != null && ft.getFrom != null) { | ||
| fieldType = ft; | ||
| } | ||
|
|
@@ -273,7 +274,11 @@ Interpretable planSelect(Expr expr) { | |
| return new EvalTestOnly(expr.getId(), op, stringOf(sel.getField()), fieldType); | ||
| } | ||
| // Build a qualifier. | ||
| Qualifier qual = attrFactory.newQualifier(opType, expr.getId(), sel.getField()); | ||
| Qualifier qual = | ||
| fieldType != null | ||
| ? new AttributeFactory.FieldQualifier( | ||
| expr.getId(), sel.getField(), fieldType, adapter) | ||
| : attrFactory.newQualifier(opType, expr.getId(), sel.getField()); | ||
|
Contributor
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. i assume this change avoids a redundant
Member
Author
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. It's a bit of repeated work, yea. |
||
| if (qual == null) { | ||
| return null; | ||
| } | ||
|
|
@@ -292,6 +297,19 @@ Interpretable planSelect(Expr expr) { | |
| return relAttr; | ||
| } | ||
|
|
||
| private FieldType findFieldType(String messageType, String fieldName) { | ||
| String key = messageType + '\n' + fieldName; | ||
| FieldType ft = fieldTypes.get(key); | ||
| if (ft != null) { | ||
| return ft; | ||
| } | ||
| ft = provider.findFieldType(messageType, fieldName); | ||
| if (ft != null) { | ||
| fieldTypes.put(key, ft); | ||
| } | ||
| return ft; | ||
| } | ||
|
|
||
| /** | ||
| * planCall creates a callable Interpretable while specializing for common functions and | ||
| * invocation patterns. Specifically, conditional operators &&, ||, ?:, and (in)equality | ||
|
|
||
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 assume its not worth caching negative lookup results?
(i have no idea how frequently this gets called and how expensive
provider.findFieldTypeis)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.
Not really, no