From 81ac9874846b3ead275f67010fcfdb49f3d2f43c Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Sat, 24 Sep 2022 08:28:16 +0100 Subject: [PATCH] Optimise variable prototype chain handling With this improvement and 53d229592df76c6dd607e40be5bea4d5e063c48e I'm measuring a 10-15% performance improvement between v5.2.3 and master using https://github.com/Jermolene/tiddlywiki-performance-test-rig --- core/modules/widgets/importvariables.js | 5 ++++- core/modules/widgets/widget.js | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/modules/widgets/importvariables.js b/core/modules/widgets/importvariables.js index 0cda68138..a73abfdcf 100644 --- a/core/modules/widgets/importvariables.js +++ b/core/modules/widgets/importvariables.js @@ -39,7 +39,10 @@ Compute the internal state of the widget ImportVariablesWidget.prototype.execute = function(tiddlerList) { var widgetPointer = this; // Got to flush all the accumulated variables - this.variables = new this.variablesConstructor(); + this.variables = Object.create(null); + if(this.parentWidget) { + Object.setPrototypeOf(this.variables,this.parentWidget.variables); + } // Get our parameters this.filter = this.getAttribute("filter"); // Compute the filter diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 0aefbada8..7034c9f37 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -38,9 +38,10 @@ Widget.prototype.initialise = function(parseTreeNode,options) { this.parseTreeNode = parseTreeNode; this.wiki = options.wiki; this.parentWidget = options.parentWidget; - this.variablesConstructor = function() {}; - this.variablesConstructor.prototype = this.parentWidget ? this.parentWidget.variables : {}; - this.variables = new this.variablesConstructor(); + this.variables = Object.create(null); + if(this.parentWidget) { + Object.setPrototypeOf(this.variables,this.parentWidget.variables); + } this.document = options.document; this.attributes = {}; this.children = [];