From 0a7c57c860f4961508817d243230d64b287520f2 Mon Sep 17 00:00:00 2001 From: Simon Huber Date: Mon, 14 Oct 2024 06:52:21 +0200 Subject: [PATCH 01/10] Update render.js --- core/modules/startup/render.js | 64 +++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/core/modules/startup/render.js b/core/modules/startup/render.js index 7206a51d023..e618a89d7fd 100644 --- a/core/modules/startup/render.js +++ b/core/modules/startup/render.js @@ -50,14 +50,46 @@ exports.startup = function() { $tw.styleElement = document.createElement("style"); $tw.styleElement.innerHTML = $tw.styleWidgetNode.assignedStyles; document.head.insertBefore($tw.styleElement,document.head.firstChild); - $tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) { + // Prepare refresh mechanism + var deferredChanges = Object.create(null), + timerId, + throttledRefreshFn = function(changes,callback,mainCondition,styleCondition) { + // Check if only tiddlers that are throttled have changed + var onlyThrottledTiddlersHaveChanged = true; + for(var title in changes) { + var tiddler = $tw.wiki.getTiddler(title); + if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || (mainCondition && tiddler.hasField("throttle.refresh.main")) || (styleCondition && tiddler.hasField("throttle.refresh.style"))))) { + onlyThrottledTiddlersHaveChanged = false; + } + } + // Defer the change if only drafts have changed + if(timerId) { + clearTimeout(timerId); + } + timerId = null; + if(onlyThrottledTiddlersHaveChanged) { + var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); + if(isNaN(timeout)) { + timeout = THROTTLE_REFRESH_TIMEOUT; + } + timerId = setTimeout(throttledRefresh,timeout); + $tw.utils.extend(deferredChanges,changes); + } else { + $tw.utils.extend(deferredChanges,changes); + callback(changes); + } + }; + function styleRefresh(changes) { if($tw.styleWidgetNode.refresh(changes,$tw.styleContainer,null)) { var newStyles = $tw.styleContainer.textContent; if(newStyles !== $tw.styleWidgetNode.assignedStyles) { $tw.styleWidgetNode.assignedStyles = newStyles; $tw.styleElement.innerHTML = $tw.styleWidgetNode.assignedStyles; } - } + } + } + $tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) { + throttledRefreshFn(changes,styleRefresh,false,true); })); // Display the $:/core/ui/PageTemplate tiddler to kick off the display $tw.perf.report("mainRender",function() { @@ -75,9 +107,6 @@ exports.startup = function() { removeItem.parentNode.removeChild(removeItem); } }); - // Prepare refresh mechanism - var deferredChanges = Object.create(null), - timerId; function refresh() { // Process the refresh $tw.hooks.invokeHook("th-page-refreshing"); @@ -89,30 +118,7 @@ exports.startup = function() { // Add the change event handler $tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) { - // Check if only tiddlers that are throttled have changed - var onlyThrottledTiddlersHaveChanged = true; - for(var title in changes) { - var tiddler = $tw.wiki.getTiddler(title); - if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh")))) { - onlyThrottledTiddlersHaveChanged = false; - } - } - // Defer the change if only drafts have changed - if(timerId) { - clearTimeout(timerId); - } - timerId = null; - if(onlyThrottledTiddlersHaveChanged) { - var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); - if(isNaN(timeout)) { - timeout = THROTTLE_REFRESH_TIMEOUT; - } - timerId = setTimeout(throttledRefresh,timeout); - $tw.utils.extend(deferredChanges,changes); - } else { - $tw.utils.extend(deferredChanges,changes); - refresh(); - } + throttledRefreshFn(changes,refresh,true,false); })); // Fix up the link between the root widget and the page container $tw.rootWidget.domNodes = [$tw.pageContainer]; From 3663757b87f386348258ba7d018494075f788d8b Mon Sep 17 00:00:00 2001 From: Simon Huber Date: Mon, 14 Oct 2024 06:53:34 +0200 Subject: [PATCH 02/10] Update windows.js --- core/modules/startup/windows.js | 57 +++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/core/modules/startup/windows.js b/core/modules/startup/windows.js index 34f45d7a589..3d4c82dd629 100644 --- a/core/modules/startup/windows.js +++ b/core/modules/startup/windows.js @@ -27,7 +27,8 @@ exports.startup = function() { // Handle open window message $tw.rootWidget.addEventListener("tm-open-window",function(event) { // Get the parameters - var refreshHandler, + var mainRefreshHandler, + styleRefreshHandler, title = event.param || event.tiddlerTitle, paramObject = event.paramObject || {}, windowTitle = paramObject.windowTitle || title, @@ -61,7 +62,8 @@ exports.startup = function() { srcDocument.title = windowTitle; srcWindow.addEventListener("beforeunload",function(event) { delete $tw.windows[windowID]; - $tw.wiki.removeEventListener("change",refreshHandler); + $tw.wiki.removeEventListener("change",styleRefreshHandler); + $tw.wiki.removeEventListener("change",mainRefreshHandler); },false); // Set up the styles var styleWidgetNode = $tw.wiki.makeTranscludeWidget("$:/core/ui/PageStylesheet",{ @@ -72,19 +74,62 @@ exports.startup = function() { styleWidgetNode.render(styleContainer,null); var styleElement = srcDocument.createElement("style"); styleElement.innerHTML = styleContainer.textContent; + styleWidgetNode.assignedStyles = styleContainer.textContent; srcDocument.head.insertBefore(styleElement,srcDocument.head.firstChild); // Render the text of the tiddler var parser = $tw.wiki.parseTiddler(template), widgetNode = $tw.wiki.makeWidget(parser,{document: srcDocument, parentWidget: $tw.rootWidget, variables: variables}); widgetNode.render(srcDocument.body,srcDocument.body.firstChild); - // Function to handle refreshes - refreshHandler = function(changes) { + // Prepare refresh mechanism + var deferredChanges = Object.create(null), + timerId, + throttledRefreshFn = function(changes,callback,mainCondition,styleCondition) { + // Check if only tiddlers that are throttled have changed + var onlyThrottledTiddlersHaveChanged = true; + for(var title in changes) { + var tiddler = $tw.wiki.getTiddler(title); + if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || (mainCondition && tiddler.hasField("throttle.refresh.main")) || (styleCondition && tiddler.hasField("throttle.refresh.style"))))) { + onlyThrottledTiddlersHaveChanged = false; + } + } + // Defer the change if only drafts have changed + if(timerId) { + clearTimeout(timerId); + } + timerId = null; + if(onlyThrottledTiddlersHaveChanged) { + var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); + if(isNaN(timeout)) { + timeout = THROTTLE_REFRESH_TIMEOUT; + } + timerId = setTimeout(throttledRefresh,timeout); + $tw.utils.extend(deferredChanges,changes); + } else { + $tw.utils.extend(deferredChanges,changes); + callback(changes); + } + }; + var styleRefresh = function(changes) { if(styleWidgetNode.refresh(changes,styleContainer,null)) { - styleElement.innerHTML = styleContainer.textContent; + var newStyles = styleContainer.textContent; + if(newStyles !== styleWidgetNode.assignedStyles) { + styleWidgetNode.assignedStyles = newStyles; + styleElement.innerHTML = styleWidgetNode.assignedStyles; + } } + }; + var mainRefresh = function(changes) { widgetNode.refresh(changes); + deferredChanges = Object.create(null); + }; + styleRefreshHandler = function(changes) { + throttledRefreshFn(changes,styleRefresh,false,true); + }; + mainRefreshHandler = function(changes) { + throttledRefreshFn(changes,mainRefresh,true,false); }; - $tw.wiki.addEventListener("change",refreshHandler); + $tw.wiki.addEventListener("change",styleRefreshHandler); + $tw.wiki.addEventListener("change",mainRefreshHandler); // Listen for keyboard shortcuts $tw.utils.addEventListeners(srcDocument,[{ name: "keydown", From 6addb77024f59825d70e50570227d003c31aabc7 Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Mon, 14 Oct 2024 07:11:38 +0200 Subject: [PATCH 03/10] add docs --- editions/tw5.com/tiddlers/mechanisms/RefreshThrottling.tid | 2 ++ 1 file changed, 2 insertions(+) diff --git a/editions/tw5.com/tiddlers/mechanisms/RefreshThrottling.tid b/editions/tw5.com/tiddlers/mechanisms/RefreshThrottling.tid index 5ae3d9645c0..d837837a57e 100644 --- a/editions/tw5.com/tiddlers/mechanisms/RefreshThrottling.tid +++ b/editions/tw5.com/tiddlers/mechanisms/RefreshThrottling.tid @@ -12,6 +12,8 @@ The rules governing refresh throttling are: ** Has the field `draft.of` ** Has the field `throttle.refresh` ** Has a title prefixed with `$:/temp/volatile/` +** <<.from-version "5.3.6">> Has the field `throttle.refresh.main` - then throttling will only occur in the main refresh +** <<.from-version "5.3.6">> Has the field `throttle.refresh.style` - then throttling will only occur in the style refresh * If the refresh cycle is to be throttled, a timer is set for the internal specified in [[$:/config/Drafts/TypingTimeout|Hidden Setting: Typing Refresh Delay]] (cancelling any previously set timer) ** When the timer fires, the refresh cycle is triggered, passing the aggregated titles of all the deferred refresh cycles From 8eddb4586af1ea24b5ad678aeda67c19a7c4169c Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Tue, 15 Oct 2024 05:09:28 +0200 Subject: [PATCH 04/10] do it correctly --- core/modules/startup/render.js | 39 ++++++++++++++++++--------------- core/modules/startup/windows.js | 27 +++++++++++++---------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/core/modules/startup/render.js b/core/modules/startup/render.js index e618a89d7fd..7e4a15cffba 100644 --- a/core/modules/startup/render.js +++ b/core/modules/startup/render.js @@ -51,9 +51,11 @@ exports.startup = function() { $tw.styleElement.innerHTML = $tw.styleWidgetNode.assignedStyles; document.head.insertBefore($tw.styleElement,document.head.firstChild); // Prepare refresh mechanism - var deferredChanges = Object.create(null), - timerId, - throttledRefreshFn = function(changes,callback,mainCondition,styleCondition) { + var mainDeferredChanges = Object.create(null), + styleDeferredChanges = Object.create(null), + mainTimerId, + styleTimerId, + throttledRefreshFn = function(changes,deferredChanges,timerId,throttledRefresh,callback,mainCondition,styleCondition) { // Check if only tiddlers that are throttled have changed var onlyThrottledTiddlersHaveChanged = true; for(var title in changes) { @@ -76,20 +78,30 @@ exports.startup = function() { $tw.utils.extend(deferredChanges,changes); } else { $tw.utils.extend(deferredChanges,changes); - callback(changes); + callback(); } }; - function styleRefresh(changes) { - if($tw.styleWidgetNode.refresh(changes,$tw.styleContainer,null)) { + function refresh() { + // Process the refresh + $tw.hooks.invokeHook("th-page-refreshing"); + $tw.pageWidgetNode.refresh(mainDeferredChanges); + mainDeferredChanges = Object.create(null); + $tw.hooks.invokeHook("th-page-refreshed"); + } + function styleRefresh() { + if($tw.styleWidgetNode.refresh(styleDeferredChanges,$tw.styleContainer,null)) { var newStyles = $tw.styleContainer.textContent; if(newStyles !== $tw.styleWidgetNode.assignedStyles) { $tw.styleWidgetNode.assignedStyles = newStyles; $tw.styleElement.innerHTML = $tw.styleWidgetNode.assignedStyles; } - } + } + styleDeferredChanges = Object.create(null); } + var mainThrottledRefresh = $tw.perf.report("throttledRefresh",refresh), + styleThrottledRefresh = $tw.perf.report("throttledRefresh",styleRefresh); $tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) { - throttledRefreshFn(changes,styleRefresh,false,true); + throttledRefreshFn(changes,styleDeferredChanges,styleTimerId,styleThrottledRefresh,styleRefresh,false,true); })); // Display the $:/core/ui/PageTemplate tiddler to kick off the display $tw.perf.report("mainRender",function() { @@ -107,18 +119,9 @@ exports.startup = function() { removeItem.parentNode.removeChild(removeItem); } }); - function refresh() { - // Process the refresh - $tw.hooks.invokeHook("th-page-refreshing"); - $tw.pageWidgetNode.refresh(deferredChanges); - deferredChanges = Object.create(null); - $tw.hooks.invokeHook("th-page-refreshed"); - } - var throttledRefresh = $tw.perf.report("throttledRefresh",refresh); - // Add the change event handler $tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) { - throttledRefreshFn(changes,refresh,true,false); + throttledRefreshFn(changes,mainDeferredChanges,mainTimerId,mainThrottledRefresh,refresh,true,false); })); // Fix up the link between the root widget and the page container $tw.rootWidget.domNodes = [$tw.pageContainer]; diff --git a/core/modules/startup/windows.js b/core/modules/startup/windows.js index 3d4c82dd629..fb5a0a79078 100644 --- a/core/modules/startup/windows.js +++ b/core/modules/startup/windows.js @@ -81,9 +81,11 @@ exports.startup = function() { widgetNode = $tw.wiki.makeWidget(parser,{document: srcDocument, parentWidget: $tw.rootWidget, variables: variables}); widgetNode.render(srcDocument.body,srcDocument.body.firstChild); // Prepare refresh mechanism - var deferredChanges = Object.create(null), - timerId, - throttledRefreshFn = function(changes,callback,mainCondition,styleCondition) { + var mainDeferredChanges = Object.create(null), + styleDeferredChanges = Object.create(null), + mainTimerId, + styleTimerId, + throttledRefreshFn = function(changes,deferredChanges,timerId,throttledRefresh,callback,mainCondition,styleCondition) { // Check if only tiddlers that are throttled have changed var onlyThrottledTiddlersHaveChanged = true; for(var title in changes) { @@ -106,27 +108,30 @@ exports.startup = function() { $tw.utils.extend(deferredChanges,changes); } else { $tw.utils.extend(deferredChanges,changes); - callback(changes); + callback(); } }; - var styleRefresh = function(changes) { - if(styleWidgetNode.refresh(changes,styleContainer,null)) { + var styleRefresh = function() { + if(styleWidgetNode.refresh(styleDeferredChanges,styleContainer,null)) { var newStyles = styleContainer.textContent; if(newStyles !== styleWidgetNode.assignedStyles) { styleWidgetNode.assignedStyles = newStyles; styleElement.innerHTML = styleWidgetNode.assignedStyles; } } + styleDeferredChanges = Object.create(null); }; - var mainRefresh = function(changes) { - widgetNode.refresh(changes); - deferredChanges = Object.create(null); + var mainRefresh = function() { + widgetNode.refresh(mainDeferredChanges); + mainDeferredChanges = Object.create(null); }; + var mainThrottledRefresh = $tw.perf.report("throttledRefresh",mainRefresh), + styleThrottledRefresh = $tw.perf.report("throttledRefresh",styleRefresh); styleRefreshHandler = function(changes) { - throttledRefreshFn(changes,styleRefresh,false,true); + throttledRefreshFn(changes,styleDeferredChanges,styleTimerId,styleThrottledRefresh,styleRefresh,false,true); }; mainRefreshHandler = function(changes) { - throttledRefreshFn(changes,mainRefresh,true,false); + throttledRefreshFn(changes,mainDeferredChanges,mainTimerId,mainThrottledRefresh,mainRefresh,true,false); }; $tw.wiki.addEventListener("change",styleRefreshHandler); $tw.wiki.addEventListener("change",mainRefreshHandler); From 7f9b5ae8f08c3f9224d7438c70fdce04765222ae Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Tue, 15 Oct 2024 05:23:44 +0200 Subject: [PATCH 05/10] differenciate between mainThrottledRefresh and styleThrottledRefresh --- core/modules/startup/render.js | 4 ++-- core/modules/startup/windows.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/modules/startup/render.js b/core/modules/startup/render.js index 7e4a15cffba..4b3561b0e48 100644 --- a/core/modules/startup/render.js +++ b/core/modules/startup/render.js @@ -98,8 +98,8 @@ exports.startup = function() { } styleDeferredChanges = Object.create(null); } - var mainThrottledRefresh = $tw.perf.report("throttledRefresh",refresh), - styleThrottledRefresh = $tw.perf.report("throttledRefresh",styleRefresh); + var mainThrottledRefresh = $tw.perf.report("throttledMainRefresh",refresh), + styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); $tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) { throttledRefreshFn(changes,styleDeferredChanges,styleTimerId,styleThrottledRefresh,styleRefresh,false,true); })); diff --git a/core/modules/startup/windows.js b/core/modules/startup/windows.js index fb5a0a79078..9f0e9d6d53e 100644 --- a/core/modules/startup/windows.js +++ b/core/modules/startup/windows.js @@ -125,8 +125,8 @@ exports.startup = function() { widgetNode.refresh(mainDeferredChanges); mainDeferredChanges = Object.create(null); }; - var mainThrottledRefresh = $tw.perf.report("throttledRefresh",mainRefresh), - styleThrottledRefresh = $tw.perf.report("throttledRefresh",styleRefresh); + var mainThrottledRefresh = $tw.perf.report("throttledMainRefresh",mainRefresh), + styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); styleRefreshHandler = function(changes) { throttledRefreshFn(changes,styleDeferredChanges,styleTimerId,styleThrottledRefresh,styleRefresh,false,true); }; From 20c2eb3ad8769f05ddd1def182a0ce496acbd213 Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Tue, 15 Oct 2024 13:47:28 +0200 Subject: [PATCH 06/10] pass options object to throttledRefreshFn --- core/modules/startup/render.js | 38 ++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/core/modules/startup/render.js b/core/modules/startup/render.js index 4b3561b0e48..1d287f2916a 100644 --- a/core/modules/startup/render.js +++ b/core/modules/startup/render.js @@ -55,30 +55,32 @@ exports.startup = function() { styleDeferredChanges = Object.create(null), mainTimerId, styleTimerId, - throttledRefreshFn = function(changes,deferredChanges,timerId,throttledRefresh,callback,mainCondition,styleCondition) { + throttledRefreshFn = function(changes,options) { + options = options || {}; // Check if only tiddlers that are throttled have changed var onlyThrottledTiddlersHaveChanged = true; for(var title in changes) { var tiddler = $tw.wiki.getTiddler(title); - if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || (mainCondition && tiddler.hasField("throttle.refresh.main")) || (styleCondition && tiddler.hasField("throttle.refresh.style"))))) { + if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || + (options.mainCondition && tiddler.hasField("throttle.refresh.main")) || (options.styleCondition && tiddler.hasField("throttle.refresh.style"))))) { onlyThrottledTiddlersHaveChanged = false; } } // Defer the change if only drafts have changed - if(timerId) { - clearTimeout(timerId); + if(options.timerId) { + clearTimeout(options.timerId); } - timerId = null; + options.timerId = null; if(onlyThrottledTiddlersHaveChanged) { var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); if(isNaN(timeout)) { timeout = THROTTLE_REFRESH_TIMEOUT; } - timerId = setTimeout(throttledRefresh,timeout); - $tw.utils.extend(deferredChanges,changes); + options.timerId = setTimeout(options.throttledRefresh,timeout); + $tw.utils.extend(options.deferredChanges,changes); } else { - $tw.utils.extend(deferredChanges,changes); - callback(); + $tw.utils.extend(options.deferredChanges,changes); + options.callback(); } }; function refresh() { @@ -101,7 +103,14 @@ exports.startup = function() { var mainThrottledRefresh = $tw.perf.report("throttledMainRefresh",refresh), styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); $tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) { - throttledRefreshFn(changes,styleDeferredChanges,styleTimerId,styleThrottledRefresh,styleRefresh,false,true); + throttledRefreshFn(changes,{ + deferredChanges: styleDeferredChanges, + timerId: styleTimerId, + throttledRefresh: styleThrottledRefresh, + callback: styleRefresh, + mainCondition: false, + styleCondition: true + }); })); // Display the $:/core/ui/PageTemplate tiddler to kick off the display $tw.perf.report("mainRender",function() { @@ -121,7 +130,14 @@ exports.startup = function() { }); // Add the change event handler $tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) { - throttledRefreshFn(changes,mainDeferredChanges,mainTimerId,mainThrottledRefresh,refresh,true,false); + throttledRefreshFn(changes,{ + deferredChanges: mainDeferredChanges, + timerId: mainTimerId, + throttledRefresh: mainThrottledRefresh, + callback: refresh, + mainCondition: true, + styleCondition: false + }); })); // Fix up the link between the root widget and the page container $tw.rootWidget.domNodes = [$tw.pageContainer]; From b755f09abc4e5d9f5f2722cd1a3b3bb911abf83c Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Tue, 15 Oct 2024 15:38:22 +0200 Subject: [PATCH 07/10] small invisible update --- core/modules/startup/render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/startup/render.js b/core/modules/startup/render.js index 1d287f2916a..5453a0c7edd 100644 --- a/core/modules/startup/render.js +++ b/core/modules/startup/render.js @@ -61,7 +61,7 @@ exports.startup = function() { var onlyThrottledTiddlersHaveChanged = true; for(var title in changes) { var tiddler = $tw.wiki.getTiddler(title); - if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || + if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || (options.mainCondition && tiddler.hasField("throttle.refresh.main")) || (options.styleCondition && tiddler.hasField("throttle.refresh.style"))))) { onlyThrottledTiddlersHaveChanged = false; } From 64019cb0b4539e4abe4b3de5c4d2733b19a60602 Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Tue, 15 Oct 2024 18:23:18 +0200 Subject: [PATCH 08/10] updates --- core/modules/startup/windows.js | 38 +++++++++++++------ .../config/PerformanceInstrumentation.tid | 2 +- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/core/modules/startup/windows.js b/core/modules/startup/windows.js index 9f0e9d6d53e..52b389fd9a0 100644 --- a/core/modules/startup/windows.js +++ b/core/modules/startup/windows.js @@ -85,30 +85,32 @@ exports.startup = function() { styleDeferredChanges = Object.create(null), mainTimerId, styleTimerId, - throttledRefreshFn = function(changes,deferredChanges,timerId,throttledRefresh,callback,mainCondition,styleCondition) { + throttledRefreshFn = function(changes,options) { + options = options || {}; // Check if only tiddlers that are throttled have changed var onlyThrottledTiddlersHaveChanged = true; for(var title in changes) { var tiddler = $tw.wiki.getTiddler(title); - if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || (mainCondition && tiddler.hasField("throttle.refresh.main")) || (styleCondition && tiddler.hasField("throttle.refresh.style"))))) { + if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || + (options.mainCondition && tiddler.hasField("throttle.refresh.main")) || (options.styleCondition && tiddler.hasField("throttle.refresh.style"))))) { onlyThrottledTiddlersHaveChanged = false; } } // Defer the change if only drafts have changed - if(timerId) { - clearTimeout(timerId); + if(options.timerId) { + clearTimeout(options.timerId); } - timerId = null; + options.timerId = null; if(onlyThrottledTiddlersHaveChanged) { var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); if(isNaN(timeout)) { timeout = THROTTLE_REFRESH_TIMEOUT; } - timerId = setTimeout(throttledRefresh,timeout); - $tw.utils.extend(deferredChanges,changes); + options.timerId = setTimeout(options.throttledRefresh,timeout); + $tw.utils.extend(options.deferredChanges,changes); } else { - $tw.utils.extend(deferredChanges,changes); - callback(); + $tw.utils.extend(options.deferredChanges,changes); + options.callback(); } }; var styleRefresh = function() { @@ -128,10 +130,24 @@ exports.startup = function() { var mainThrottledRefresh = $tw.perf.report("throttledMainRefresh",mainRefresh), styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); styleRefreshHandler = function(changes) { - throttledRefreshFn(changes,styleDeferredChanges,styleTimerId,styleThrottledRefresh,styleRefresh,false,true); + throttledRefreshFn(changes,{ + deferredChanged: styleDeferredChanges, + timerId: styleTimerId, + throttledRefresh: styleThrottledRefresh, + callback: styleRefresh, + mainCondition: false, + styleCondition: true + }); }; mainRefreshHandler = function(changes) { - throttledRefreshFn(changes,mainDeferredChanges,mainTimerId,mainThrottledRefresh,mainRefresh,true,false); + throttledRefreshFn(changes,{ + deferredChanges: mainDeferredChanges, + timerId: mainTimerId, + throttledRefresh: mainThrottledRefresh, + callback: mainRefresh, + mainCondition: true, + styleCondition: false + }); }; $tw.wiki.addEventListener("change",styleRefreshHandler); $tw.wiki.addEventListener("change",mainRefreshHandler); diff --git a/core/wiki/config/PerformanceInstrumentation.tid b/core/wiki/config/PerformanceInstrumentation.tid index ccae6842e27..e4220f287d3 100644 --- a/core/wiki/config/PerformanceInstrumentation.tid +++ b/core/wiki/config/PerformanceInstrumentation.tid @@ -1,2 +1,2 @@ title: $:/config/Performance/Instrumentation -text: no +text: yes From 9da4964ee9e3ca13484775693b4bcc908447d4bd Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Tue, 15 Oct 2024 21:18:56 +0200 Subject: [PATCH 09/10] make this work --- core/modules/startup/render.js | 28 ++++++++++++++++++---------- core/modules/startup/windows.js | 28 ++++++++++++++++++---------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/core/modules/startup/render.js b/core/modules/startup/render.js index 5453a0c7edd..10a90b9380b 100644 --- a/core/modules/startup/render.js +++ b/core/modules/startup/render.js @@ -59,6 +59,7 @@ exports.startup = function() { options = options || {}; // Check if only tiddlers that are throttled have changed var onlyThrottledTiddlersHaveChanged = true; + var deferredChanges = options.mainCondition ? mainDeferredChanges : styleDeferredChanges; for(var title in changes) { var tiddler = $tw.wiki.getTiddler(title); if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || @@ -67,19 +68,30 @@ exports.startup = function() { } } // Defer the change if only drafts have changed - if(options.timerId) { - clearTimeout(options.timerId); + if(options.mainCondition) { + if(mainTimerId) { + clearTimeout(mainTimerId); + } + mainTimerId = null; + } else if(options.styleCondition) { + if(styleTimerId) { + clearTimeout(styleTimerId); + } + styleTimerId = null; } - options.timerId = null; if(onlyThrottledTiddlersHaveChanged) { var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); if(isNaN(timeout)) { timeout = THROTTLE_REFRESH_TIMEOUT; } - options.timerId = setTimeout(options.throttledRefresh,timeout); - $tw.utils.extend(options.deferredChanges,changes); + if(options.mainCondition) { + mainTimerId = setTimeout(options.throttledRefresh,timeout); + } else if(options.styleCondition) { + styleTimerId = setTimeout(options.throttledRefresh,timeout); + } + $tw.utils.extend(deferredChanges,changes); } else { - $tw.utils.extend(options.deferredChanges,changes); + $tw.utils.extend(deferredChanges,changes); options.callback(); } }; @@ -104,8 +116,6 @@ exports.startup = function() { styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); $tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) { throttledRefreshFn(changes,{ - deferredChanges: styleDeferredChanges, - timerId: styleTimerId, throttledRefresh: styleThrottledRefresh, callback: styleRefresh, mainCondition: false, @@ -131,8 +141,6 @@ exports.startup = function() { // Add the change event handler $tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) { throttledRefreshFn(changes,{ - deferredChanges: mainDeferredChanges, - timerId: mainTimerId, throttledRefresh: mainThrottledRefresh, callback: refresh, mainCondition: true, diff --git a/core/modules/startup/windows.js b/core/modules/startup/windows.js index 52b389fd9a0..83d136f8f92 100644 --- a/core/modules/startup/windows.js +++ b/core/modules/startup/windows.js @@ -89,6 +89,7 @@ exports.startup = function() { options = options || {}; // Check if only tiddlers that are throttled have changed var onlyThrottledTiddlersHaveChanged = true; + var deferredChanges = options.mainCondition ? mainDeferredChanges : styleDeferredChanges; for(var title in changes) { var tiddler = $tw.wiki.getTiddler(title); if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || @@ -97,19 +98,30 @@ exports.startup = function() { } } // Defer the change if only drafts have changed - if(options.timerId) { - clearTimeout(options.timerId); + if(options.mainCondition) { + if(mainTimerId) { + clearTimeout(mainTimerId); + } + mainTimerId = null; + } else if(options.styleCondition) { + if(styleTimerId) { + clearTimeout(styleTimerId); + } + styleTimerId = null; } - options.timerId = null; if(onlyThrottledTiddlersHaveChanged) { var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); if(isNaN(timeout)) { timeout = THROTTLE_REFRESH_TIMEOUT; } - options.timerId = setTimeout(options.throttledRefresh,timeout); - $tw.utils.extend(options.deferredChanges,changes); + if(options.mainCondition) { + mainTimerId = setTimeout(options.throttledRefresh,timeout); + } else if(options.styleCondition) { + styleTimerId = setTimeout(options.throttledRefresh,timeout); + } + $tw.utils.extend(deferredChanges,changes); } else { - $tw.utils.extend(options.deferredChanges,changes); + $tw.utils.extend(deferredChanges,changes); options.callback(); } }; @@ -131,8 +143,6 @@ exports.startup = function() { styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); styleRefreshHandler = function(changes) { throttledRefreshFn(changes,{ - deferredChanged: styleDeferredChanges, - timerId: styleTimerId, throttledRefresh: styleThrottledRefresh, callback: styleRefresh, mainCondition: false, @@ -141,8 +151,6 @@ exports.startup = function() { }; mainRefreshHandler = function(changes) { throttledRefreshFn(changes,{ - deferredChanges: mainDeferredChanges, - timerId: mainTimerId, throttledRefresh: mainThrottledRefresh, callback: mainRefresh, mainCondition: true, From c4b805c2adecd8e4156170e07220aeabbd4dca47 Mon Sep 17 00:00:00 2001 From: BurningTreeC Date: Tue, 15 Oct 2024 21:44:57 +0200 Subject: [PATCH 10/10] disable performance instrumentation --- core/wiki/config/PerformanceInstrumentation.tid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/wiki/config/PerformanceInstrumentation.tid b/core/wiki/config/PerformanceInstrumentation.tid index e4220f287d3..ccae6842e27 100644 --- a/core/wiki/config/PerformanceInstrumentation.tid +++ b/core/wiki/config/PerformanceInstrumentation.tid @@ -1,2 +1,2 @@ title: $:/config/Performance/Instrumentation -text: yes +text: no