Skip to content
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

Expose squash method on SharedTreeBranch #23170

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

noencke
Copy link
Contributor

@noencke noencke commented Nov 21, 2024

Description

This exposes the ability to directly remove or squash commits on the head of a SharedTreeBranch. Currently this functionality is used when aborting or committing transactions. In addition to being a nice refactor in general, this will assist with future efforts to remove the notion of transactionality from branches.

@noencke noencke requested a review from a team as a code owner November 21, 2024 00:51
@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree base: main PRs targeted against main branch labels Nov 21, 2024
}

const removedCommits: GraphCommit<TChange>[] = [];
const ancestor = findAncestor([this.head, removedCommits], (c) => c === startCommit);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is, for now, introducing duplicated work (because "removedCommits" is already stored by the transaction state). However, it is necessary to do this independently if we want to later remove transactions from branches, which is the goal. I don't expect this to actually regress any behavior, except (maybe?) in the case of an absolutely massive transaction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't bother me :)

Copy link
Collaborator

@msfluid-bot msfluid-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Coverage Summary

↑ packages.dds.tree.src.shared-tree-core:
Line Coverage Change: 0.03%    Branch Coverage Change: 0.98%
Metric NameBaseline coveragePR coverageCoverage Diff
Branch Coverage 92.59% 93.57% ↑ 0.98%
Line Coverage 97.15% 97.18% ↑ 0.03%

Baseline commit: 645a1a0
Baseline build: 309185
Happy Coding!!

Code coverage comparison check passed!!

@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Nov 21, 2024

@fluid-example/bundle-size-tests: +505 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 467.24 KB 467.27 KB +35 Bytes
azureClient.js 564.01 KB 564.06 KB +49 Bytes
connectionState.js 724 Bytes 724 Bytes No change
containerRuntime.js 263.43 KB 263.45 KB +14 Bytes
fluidFramework.js 428.84 KB 428.98 KB +144 Bytes
loader.js 134.18 KB 134.19 KB +14 Bytes
map.js 42.71 KB 42.71 KB +7 Bytes
matrix.js 150.15 KB 150.16 KB +7 Bytes
odspClient.js 529.85 KB 529.89 KB +49 Bytes
odspDriver.js 97.88 KB 97.9 KB +21 Bytes
odspPrefetchSnapshot.js 42.81 KB 42.83 KB +14 Bytes
sharedString.js 166.23 KB 166.24 KB +7 Bytes
sharedTree.js 419.3 KB 419.43 KB +137 Bytes
Total Size 3.38 MB 3.38 MB +505 Bytes

Baseline commit: 645a1a0

Generated by 🚫 dangerJS against 1806420

Comment on lines +461 to +471
if (c !== commit) {
const revision = this.mintRevisionTag();
const inverse = this.changeFamily.rebaser.changeRevision(
this.changeFamily.rebaser.invert(c, true, revision),
revision,
c.revision,
);

inverses.push(tagRollbackInverse(inverse, revision, c.revision));
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of having side effects within the findAncestor callstack. I don't think the contract for findAncestor should be so specific as to guarantee this will work as expected (it currently hints that way but I don't think it should). Seems like the legibility of the code would go up anyway if we pulled this out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I like this way. If you pull it out, then you have to:

  1. Write an additional loop...
  2. ...which is a backwards loop, which means you can't use for of but have to use indices...
  3. ...which means you have to assert that the read in every iteration is not undefined...

You can see this in the equivalent code that was removed from abortTransaction. In terms of legibility and code niceness, I definitely prefer this version.

Is there a way we can strengthen the contract of findAncestor to your liking? It already says "predicate - a function which will be evaluated on every ancestor of descendant until it returns true." Are you concerned that it doesn't specify the order that it evaluates the ancestors, or something? We could change it to "...on each ancestor (in ascending order) of descendant...".

I'm generally a fan of writing "functional-style" code - i.e. chaining steps together sequentially rather than trying to do two things at once like is being done here. But that's because it usually makes the code prettier - in this case it makes it worse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I guess the true "functional-style" way to do it would be to reverse() the array before iterating. But I don't think we want to do that for perf :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dds: tree area: dds Issues related to distributed data structures base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants