Repository navigation
Reuse the combined tag of a cache that reads the same tags again #21664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NullVoxPopuli-ai-agent
wants to merge
5
commits into
emberjs:main
Choose a base branch
from
NullVoxPopuli-ai-agent:nvp/reuse-frame-tag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+292
−2
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8610111
Reuse the combined tag of a tracking frame
NullVoxPopuli 4048c0c
Keep the reuse check out of Tracker#combine
NullVoxPopuli 6ab63a1
Reuse the combined tag in the frame of a cache only
NullVoxPopuli e0ff7fb
Test that a cache keeps its tag
NullVoxPopuli 12bc8d4
Use steps in the tests of the cache tag
NullVoxPopuli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -448,6 +448,199 @@ module('@glimmer/validator: tracking', () => { | |
| assert.deepEqual(getValue(outerCache), [3, 2], 'memoized result returned correctly'); | ||
| }); | ||
|
|
||
| /** | ||
| * The tag that a cache has after a read. | ||
| * | ||
| * The outer frame consumes only the tag of the cache, | ||
| * and a frame with one tag returns that tag. | ||
| */ | ||
| function tagOf(cache: ReturnType<typeof createCache>) { | ||
| beginTrackFrame(); | ||
| getValue(cache); | ||
|
|
||
| return endTrackFrame(); | ||
| } | ||
|
|
||
| test('it keeps its tag if it consumes the same tags in the next run', (assert) => { | ||
| let tag1 = createTag(); | ||
| let tag2 = createTag(); | ||
|
|
||
| let cache = createCache(() => { | ||
| assert.step('cache reads tag1 and tag2'); | ||
|
|
||
| consumeTag(tag1); | ||
| consumeTag(tag2); | ||
| }); | ||
|
|
||
| let first = tagOf(cache); | ||
|
|
||
| assert.verifySteps(['cache reads tag1 and tag2']); | ||
|
|
||
| dirtyTag(tag1); | ||
|
|
||
| let second = tagOf(cache); | ||
|
|
||
| assert.verifySteps(['cache reads tag1 and tag2'], 'the cache ran again'); | ||
| assert.strictEqual(second, first, 'the cache has the tag of its first run'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noice |
||
| }); | ||
|
|
||
| test('it gets a new tag if it consumes other tags in the next run', (assert) => { | ||
| let tag1 = createTag(); | ||
| let tag2 = createTag(); | ||
| let tag3 = createTag(); | ||
| let useThird = false; | ||
|
|
||
| let cache = createCache(() => { | ||
| consumeTag(tag1); | ||
|
|
||
| if (useThird) { | ||
| assert.step('cache reads tag1 and tag3'); | ||
| consumeTag(tag3); | ||
| } else { | ||
| assert.step('cache reads tag1 and tag2'); | ||
| consumeTag(tag2); | ||
| } | ||
| }); | ||
|
|
||
| let first = tagOf(cache); | ||
|
|
||
| assert.verifySteps(['cache reads tag1 and tag2']); | ||
|
|
||
| useThird = true; | ||
| dirtyTag(tag1); | ||
|
|
||
| let second = tagOf(cache); | ||
|
|
||
| assert.verifySteps(['cache reads tag1 and tag3'], 'the cache ran again'); | ||
| assert.notStrictEqual(second, first); | ||
| }); | ||
|
|
||
| test('it gets a new tag if it consumes the same tags in another order', (assert) => { | ||
| let tag1 = createTag(); | ||
| let tag2 = createTag(); | ||
| let swap = false; | ||
|
|
||
| let cache = createCache(() => { | ||
| if (swap) { | ||
| assert.step('cache reads tag2, then tag1'); | ||
| consumeTag(tag2); | ||
| consumeTag(tag1); | ||
| } else { | ||
| assert.step('cache reads tag1, then tag2'); | ||
| consumeTag(tag1); | ||
| consumeTag(tag2); | ||
| } | ||
| }); | ||
|
|
||
| let first = tagOf(cache); | ||
|
|
||
| assert.verifySteps(['cache reads tag1, then tag2']); | ||
|
|
||
| swap = true; | ||
| dirtyTag(tag1); | ||
|
|
||
| let second = tagOf(cache); | ||
|
|
||
| assert.verifySteps(['cache reads tag2, then tag1'], 'the cache ran again'); | ||
| assert.notStrictEqual(second, first); | ||
|
|
||
| let snapshot = valueForTag(second); | ||
|
|
||
| dirtyTag(tag2); | ||
| assert.notOk(validateTag(second, snapshot), 'the new tag follows both tags'); | ||
| }); | ||
|
|
||
| test('it tracks the new tags if the tags change between two runs', (assert) => { | ||
| let tag1 = createTag(); | ||
| let tag2 = createTag(); | ||
| let tag3 = createTag(); | ||
| let useThird = false; | ||
|
|
||
| let cache = createCache(() => { | ||
| consumeTag(tag1); | ||
|
|
||
| if (useThird) { | ||
| assert.step('cache reads tag1 and tag3'); | ||
| consumeTag(tag3); | ||
| } else { | ||
| assert.step('cache reads tag1 and tag2'); | ||
| consumeTag(tag2); | ||
| } | ||
| }); | ||
|
|
||
| getValue(cache); | ||
| assert.verifySteps(['cache reads tag1 and tag2']); | ||
|
|
||
| dirtyTag(tag2); | ||
| getValue(cache); | ||
| assert.verifySteps(['cache reads tag1 and tag2'], 'the cache ran again with the same tags'); | ||
|
|
||
| dirtyTag(tag2); | ||
| getValue(cache); | ||
| assert.verifySteps(['cache reads tag1 and tag2'], 'the reused tag still follows its tags'); | ||
|
|
||
| useThird = true; | ||
| dirtyTag(tag1); | ||
| getValue(cache); | ||
| assert.verifySteps(['cache reads tag1 and tag3']); | ||
|
|
||
| dirtyTag(tag2); | ||
| getValue(cache); | ||
| assert.verifySteps([], 'the cache does not depend on the old tag'); | ||
|
|
||
| dirtyTag(tag3); | ||
| getValue(cache); | ||
| assert.verifySteps(['cache reads tag1 and tag3'], 'the cache depends on the new tag'); | ||
| }); | ||
|
|
||
| test('an outer cache runs again if a tag of a reused inner tag changes', (assert) => { | ||
| let tag1 = createTag(); | ||
| let tag2 = createTag(); | ||
| let tag3 = createTag(); | ||
|
|
||
| let inner = createCache(() => { | ||
| assert.step('inner reads tag1 and tag2'); | ||
|
|
||
| consumeTag(tag1); | ||
| consumeTag(tag2); | ||
| }); | ||
|
|
||
| let outer = createCache(() => { | ||
| assert.step('outer reads tag3 and inner'); | ||
|
|
||
| consumeTag(tag3); | ||
| getValue(inner); | ||
| }); | ||
|
|
||
| getValue(outer); | ||
| assert.verifySteps(['outer reads tag3 and inner', 'inner reads tag1 and tag2']); | ||
|
|
||
| dirtyTag(tag1); | ||
| getValue(outer); | ||
| assert.verifySteps( | ||
| ['outer reads tag3 and inner', 'inner reads tag1 and tag2'], | ||
| 'the inner cache ran again with the same tags' | ||
| ); | ||
|
|
||
| dirtyTag(tag2); | ||
| getValue(outer); | ||
| assert.verifySteps( | ||
| ['outer reads tag3 and inner', 'inner reads tag1 and tag2'], | ||
| 'the outer cache follows the reused inner tag' | ||
| ); | ||
|
|
||
| dirtyTag(tag3); | ||
| getValue(outer); | ||
| assert.verifySteps(['outer reads tag3 and inner'], 'the inner cache did not run again'); | ||
|
|
||
| dirtyTag(tag1); | ||
| getValue(outer); | ||
| assert.verifySteps( | ||
| ['outer reads tag3 and inner', 'inner reads tag1 and tag2'], | ||
| 'the outer cache still follows the inner tag' | ||
| ); | ||
| }); | ||
|
|
||
| test('isTracking works within a memoized function and untrack frame', (assert) => { | ||
| assert.notOk(isTracking()); | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the reuse here -- no new tracked things were encountered, so re-calling
combineis a little silly