From b3414b3ae0b736e0648a8f70c191144e758e93d3 Mon Sep 17 00:00:00 2001 From: Mahatma Kollu Date: Tue, 17 Dec 2024 13:36:49 -0500 Subject: [PATCH 1/3] lastCompute --- docs/api-reference/graph/types/graphobject.md | 13 ++++++++++++- src/Animation/ExternalTime.luau | 1 + src/Animation/Spring.luau | 1 + src/Animation/Stopwatch.luau | 1 + src/Animation/Tween.luau | 1 + src/Graph/evaluate.luau | 3 ++- src/State/Computed.luau | 1 + src/State/Value.luau | 1 + src/Types.luau | 1 + test/Spec/Graph/evaluate.spec.luau | 1 + test/Spec/Memory/insert.spec.luau | 7 ++++--- test/Util/Graphs.luau | 1 + 12 files changed, 27 insertions(+), 5 deletions(-) diff --git a/docs/api-reference/graph/types/graphobject.md b/docs/api-reference/graph/types/graphobject.md index 03d02b135..ef2fafa15 100644 --- a/docs/api-reference/graph/types/graphobject.md +++ b/docs/api-reference/graph/types/graphobject.md @@ -15,9 +15,10 @@ export type GraphObject = ScopedObject & { dependencySet: {[GraphObject]: unknown}, dependentSet: {[GraphObject]: unknown}, lastChange: number?, + lastCompute: number?, timeliness: "lazy" | "eager", validity: "valid" | "invalid" | "busy", - _evaluate: (GraphObject, lastChange: number?) -> boolean + _evaluate: (GraphObject) -> boolean } ``` @@ -75,6 +76,16 @@ object. The `os.clock()` time of this object's most recent meaningful change, or `nil` if the object is newly created. +

+ lastCompute + + : number? + +

+ +The `os.clock()` time of when this object was most recently computed, or `nil` +if the object is newly created. +

timeliness diff --git a/src/Animation/ExternalTime.luau b/src/Animation/ExternalTime.luau index 8e18ce204..e3adfaf26 100644 --- a/src/Animation/ExternalTime.luau +++ b/src/Animation/ExternalTime.luau @@ -39,6 +39,7 @@ local function ExternalTime( createdAt = createdAt, dependentSet = {}, lastChange = nil, + lastCompute = nil, scope = scope, validity = "invalid" }, diff --git a/src/Animation/Spring.luau b/src/Animation/Spring.luau index 9b95cdbba..4b781e74d 100644 --- a/src/Animation/Spring.luau +++ b/src/Animation/Spring.luau @@ -84,6 +84,7 @@ local function Spring( dependencySet = {}, dependentSet = {}, lastChange = nil, + lastCompute = nil, scope = scope, validity = "invalid", _activeDamping = -1, diff --git a/src/Animation/Stopwatch.luau b/src/Animation/Stopwatch.luau index b2e330c9b..f93a56edd 100644 --- a/src/Animation/Stopwatch.luau +++ b/src/Animation/Stopwatch.luau @@ -53,6 +53,7 @@ local function Stopwatch( dependencySet = {}, dependentSet = {}, lastChange = nil, + lastCompute = nil, scope = scope, validity = "invalid", _EXTREMELY_DANGEROUS_usedAsValue = 0, diff --git a/src/Animation/Tween.luau b/src/Animation/Tween.luau index f8d042ed3..30975c911 100644 --- a/src/Animation/Tween.luau +++ b/src/Animation/Tween.luau @@ -70,6 +70,7 @@ local function Tween( dependencySet = {}, dependentSet = {}, lastChange = nil, + lastCompute = nil, scope = scope, validity = "invalid", _activeDuration = nil, diff --git a/src/Graph/evaluate.luau b/src/Graph/evaluate.luau index 59c747fd8..be3a64abd 100644 --- a/src/Graph/evaluate.luau +++ b/src/Graph/evaluate.luau @@ -28,7 +28,7 @@ local function evaluate( if not needsComputation then for dependency in target.dependencySet do evaluate(dependency, false) - if dependency.lastChange > target.lastChange then + if dependency.lastChange > target.lastCompute then needsComputation = true break end @@ -42,6 +42,7 @@ local function evaluate( end target.validity = "busy" targetMeaningfullyChanged = target:_evaluate() or firstEvaluation + target.lastCompute = os.clock() end if targetMeaningfullyChanged then target.lastChange = os.clock() diff --git a/src/State/Computed.luau b/src/State/Computed.luau index df09ed2fb..0603269b4 100644 --- a/src/State/Computed.luau +++ b/src/State/Computed.luau @@ -60,6 +60,7 @@ local function Computed( dependencySet = {}, dependentSet = {}, lastChange = nil, + lastCompute = nil, scope = scope, validity = "invalid", _EXTREMELY_DANGEROUS_usedAsValue = nil, diff --git a/src/State/Value.luau b/src/State/Value.luau index b96802543..11f3539e1 100644 --- a/src/State/Value.luau +++ b/src/State/Value.luau @@ -42,6 +42,7 @@ local function Value( createdAt = createdAt, dependentSet = {}, lastChange = os.clock(), + lastCompute = os.clock(), scope = scope, validity = "valid", _EXTREMELY_DANGEROUS_usedAsValue = initialValue diff --git a/src/Types.luau b/src/Types.luau index ddecd4092..d26737e47 100644 --- a/src/Types.luau +++ b/src/Types.luau @@ -78,6 +78,7 @@ export type GraphObject = ScopedObject & { dependencySet: {[GraphObject]: unknown}, dependentSet: {[GraphObject]: unknown}, lastChange: number?, + lastCompute: number?, timeliness: "lazy" | "eager", validity: "valid" | "invalid" | "busy", _evaluate: (GraphObject) -> boolean diff --git a/test/Spec/Graph/evaluate.spec.luau b/test/Spec/Graph/evaluate.spec.luau index 9d53aaf15..112fd5849 100644 --- a/test/Spec/Graph/evaluate.spec.luau +++ b/test/Spec/Graph/evaluate.spec.luau @@ -415,6 +415,7 @@ return function() local seen = {} for _, searchTarget in searchNow do searchTarget.lastChange = -depth + searchTarget.lastCompute = -depth searchTarget.validity = if depth == 0 then "valid" else "invalid" for dependent in searchTarget.dependentSet do if seen[dependent] then diff --git a/test/Spec/Memory/insert.spec.luau b/test/Spec/Memory/insert.spec.luau index 87c44e6cd..6adae15dd 100644 --- a/test/Spec/Memory/insert.spec.luau +++ b/test/Spec/Memory/insert.spec.luau @@ -73,8 +73,9 @@ return function() local returnedDestroy, returnedDestroy2 = insert(scope, onDestroy, onDestroy2) expect(returnedDestroy).to.equal(onDestroy) expect(returnedDestroy2).to.equal(onDestroy2) - expect(#scope).to.equal(2) - doCleanup(scope) - expect(counter).to.equal(3) + print("AQUI!") + -- expect(#scope).to.equal(2) + -- doCleanup(scope) + -- expect(counter).to.equal(3) end) end diff --git a/test/Util/Graphs.luau b/test/Util/Graphs.luau index d017a7ab8..7faedf390 100644 --- a/test/Util/Graphs.luau +++ b/test/Util/Graphs.luau @@ -533,6 +533,7 @@ function Graphs.make( dependencySet = {}, dependentSet = {}, lastChange = nil, + lastCompute = nil, timeliness = "lazy" :: "lazy", validity = "valid" :: "valid", _evaluate = function() From a45ba9ed5b9f654c07c11dc402dc98a26e356226 Mon Sep 17 00:00:00 2001 From: Mahatma Kollu Date: Tue, 17 Dec 2024 13:42:15 -0500 Subject: [PATCH 2/3] Update evaluate.luau --- src/Graph/evaluate.luau | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Graph/evaluate.luau b/src/Graph/evaluate.luau index be3a64abd..6161fd17e 100644 --- a/src/Graph/evaluate.luau +++ b/src/Graph/evaluate.luau @@ -21,7 +21,7 @@ local function evaluate( if target.validity == "busy" then return External.logError("infiniteLoop") end - local firstEvaluation = target.lastChange == nil + local firstEvaluation = target.lastCompute == nil or target.lastChange == nil local isInvalid = target.validity == "invalid" if firstEvaluation or isInvalid or forceComputation then local needsComputation = firstEvaluation or forceComputation From a9ca82a08fad435e001dab59a44f2eacbfc033c8 Mon Sep 17 00:00:00 2001 From: Infinitum Date: Wed, 18 Dec 2024 12:53:43 -0500 Subject: [PATCH 3/3] Update insert.spec.luau --- test/Spec/Memory/insert.spec.luau | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/Spec/Memory/insert.spec.luau b/test/Spec/Memory/insert.spec.luau index 6adae15dd..87c44e6cd 100644 --- a/test/Spec/Memory/insert.spec.luau +++ b/test/Spec/Memory/insert.spec.luau @@ -73,9 +73,8 @@ return function() local returnedDestroy, returnedDestroy2 = insert(scope, onDestroy, onDestroy2) expect(returnedDestroy).to.equal(onDestroy) expect(returnedDestroy2).to.equal(onDestroy2) - print("AQUI!") - -- expect(#scope).to.equal(2) - -- doCleanup(scope) - -- expect(counter).to.equal(3) + expect(#scope).to.equal(2) + doCleanup(scope) + expect(counter).to.equal(3) end) end