From 547ea6b7caab444d5453cfcc0554405b14b272b8 Mon Sep 17 00:00:00 2001 From: REllEK-IO Date: Thu, 12 Oct 2023 13:02:28 -0700 Subject: [PATCH 1/2] Prevented potentially memory bloat and made note in StagePlanner md --- StagePlanner.md | 6 +++++- package.json | 2 +- src/model/stagePlanner.ts | 33 +++++++++++++++++++++++++++------ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/StagePlanner.md b/StagePlanner.md index 419942e..800a71f 100644 --- a/StagePlanner.md +++ b/StagePlanner.md @@ -120,10 +120,14 @@ const plan = axium.stage('Stage DispatchOptions Test', } ]); ``` -To prevent action overflow, each stage is paying attention to consecutive actions of the same type. In an action overflow state, sequentially the overflow will call the same dispatch before called the next dispatch even if within the same stage. +To prevent action overflow, each stage is paying attention to consecutive actions of the same type. Noting that this can likewise be overwhelmed via a debounce set to 0. If debounce 0 is utilized, the current stage should change. Keep in mind behind the scenes during a STRX runtime, there will be multiple strategies running concurrently. Observe the runCount specified in this example. Please look to the STRX's tests folder. +To save on potential memory bloat we are only keeping track of the most recent valid 5 actions per stage to prevent action overflow. This may change in the future pending some stage that requires a larger bandwidth of actions. Likewise the amount of actions in each stage should be limited regardless. + +Lastly, in an action overflow state, sequentially the overflow will call the same dispatch before calling the next dispatch even if within the same stage. Pay attention to the example above and the final console.log() output. + ## Stage Planner within your Principle STRX is designed to be ran primarily through its loaded concepts and their associated principles. To prevent unexpected behaviors in your own principles. Please utilize the supplied KeyedSelector for axium's open property to begin the stage of your concepts. ```typescript diff --git a/package.json b/package.json index dc29559..4442021 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@phuire/strx", - "version": "0.0.27", + "version": "0.0.28", "description": "Unified Turing Machine", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/model/stagePlanner.ts b/src/model/stagePlanner.ts index 589f0ed..84782e5 100644 --- a/src/model/stagePlanner.ts +++ b/src/model/stagePlanner.ts @@ -147,12 +147,33 @@ const handleStageDelimiter = goodAction = false; } } else if (stageDelimiter) { - stageDelimiter = { - stage: plan.stage, - prevActions: [...stageDelimiter.prevActions, action.type], - unionExpiration: [...stageDelimiter.unionExpiration, action.expiration], - runOnceMap: new Map() - }; + if (stageDelimiter.prevActions.length > 4) { + stageDelimiter = { + stage: plan.stage, + prevActions: [ + stageDelimiter.prevActions[1], + stageDelimiter.prevActions[2], + stageDelimiter.prevActions[3], + stageDelimiter.prevActions[4], + action.type + ], + unionExpiration: [ + stageDelimiter.unionExpiration[1], + stageDelimiter.unionExpiration[2], + stageDelimiter.unionExpiration[3], + stageDelimiter.unionExpiration[4], + action.expiration + ], + runOnceMap: new Map() + }; + } else { + stageDelimiter = { + stage: plan.stage, + prevActions: [...stageDelimiter.prevActions, action.type], + unionExpiration: [...stageDelimiter.unionExpiration, action.expiration], + runOnceMap: new Map() + }; + } } else { stageDelimiter = { stage: plan.stage, From 77a89e08c8d94e3b79a3c3ea5f2065952fcfc05d Mon Sep 17 00:00:00 2001 From: REllEK-IO Date: Thu, 12 Oct 2023 13:12:42 -0700 Subject: [PATCH 2/2] Further improved stageDelimiter memory management --- package.json | 2 +- src/model/stagePlanner.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4442021..200fdae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@phuire/strx", - "version": "0.0.28", + "version": "0.0.29", "description": "Unified Turing Machine", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/model/stagePlanner.ts b/src/model/stagePlanner.ts index 84782e5..543f574 100644 --- a/src/model/stagePlanner.ts +++ b/src/model/stagePlanner.ts @@ -251,6 +251,12 @@ export class UnifiedSubject extends Subject { if (options?.setStage) { plan.stage = options.setStage; } + if (options?.iterateStage || (options?.setStage && options.setStage !== plan.stage)) { + stageDelimiter.prevActions = []; + stageDelimiter.unionExpiration = []; + stageDelimiter.runOnceMap = new Map(); + this.stageDelimiters.set(key, stageDelimiter); + } // Horrifying // Keep in place, this prevents branch prediction from creating ghost actions if there is an action overflow. if (plan.stageFailed === -1) {