Skip to content

Commit

Permalink
cache also undefined values in option resolver (#9661)
Browse files Browse the repository at this point in the history
Otherwise, repeated lookups of undefined properties always trigger the
comparatively expensive resolution. This can be the case for example in
_calculateBarIndexPixels() in controller.bar.js when looking up
options.skipNull and options.maxBarThickness, which is done for each bar
in a bar chart.
  • Loading branch information
Flupp committed Oct 4, 2021
1 parent e1ae5e6 commit 93fcec5
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/helpers/helpers.config.js
Expand Up @@ -181,17 +181,13 @@ const readKey = (prefix, name) => prefix ? prefix + _capitalize(name) : name;
const needsSubResolver = (prop, value) => isObject(value) && prop !== 'adapters';

function _cached(target, prop, resolve) {
let value = target[prop]; // cached value
if (defined(value)) {
return value;
if (Object.prototype.hasOwnProperty.call(target, prop)) {
return target[prop];
}

value = resolve();

if (defined(value)) {
// cache the resolved value
target[prop] = value;
}
const value = resolve();
// cache the resolved value
target[prop] = value;
return value;
}

Expand Down

0 comments on commit 93fcec5

Please sign in to comment.