Skip to content

Commit

Permalink
Avoid deoptimizations in expression evaluation (#7334)
Browse files Browse the repository at this point in the history
* avoid some JS deopts in expression evaluation

* update deopt fix

* update deopt fix 2
  • Loading branch information
mourner authored Sep 26, 2018
1 parent 6ad95cb commit c612e07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/style-spec/expression/evaluation_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class EvaluationContext {
_parseColorCache: {[string]: ?Color};

constructor() {
this.globals = (null: any);
this.feature = null;
this.featureState = null;
this._parseColorCache = {};
}

Expand Down
19 changes: 5 additions & 14 deletions src/style-spec/expression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,17 @@ export class StyleExpression {
_evaluator: EvaluationContext;
_defaultValue: Value;
_warningHistory: {[key: string]: boolean};
_enumValues: {[string]: any};
_enumValues: ?{[string]: any};

constructor(expression: Expression, propertySpec: StylePropertySpecification) {
this.expression = expression;
this._warningHistory = {};
this._evaluator = new EvaluationContext();
this._defaultValue = getDefaultValue(propertySpec);
if (propertySpec.type === 'enum') {
this._enumValues = propertySpec.values;
}
this._enumValues = propertySpec.type === 'enum' ? propertySpec.values : null;
}

evaluateWithoutErrorHandling(globals: GlobalProperties, feature?: Feature, featureState?: FeatureState): any {
if (!this._evaluator) {
this._evaluator = new EvaluationContext();
}

this._evaluator.globals = globals;
this._evaluator.feature = feature;
this._evaluator.featureState = featureState;
Expand All @@ -71,13 +66,9 @@ export class StyleExpression {
}

evaluate(globals: GlobalProperties, feature?: Feature, featureState?: FeatureState): any {
if (!this._evaluator) {
this._evaluator = new EvaluationContext();
}

this._evaluator.globals = globals;
this._evaluator.feature = feature;
this._evaluator.featureState = featureState;
this._evaluator.feature = feature || null;
this._evaluator.featureState = featureState || null;

try {
const val = this.expression.evaluate(this._evaluator);
Expand Down

0 comments on commit c612e07

Please sign in to comment.