Skip to content

Conversation

@ChrisPenner
Copy link
Member

@ChrisPenner ChrisPenner commented Sep 9, 2025

Overview

discardHistory and friends was squashing branches in such a way that we'd always rehash them.
This change avoids redundant re-hashing where possible.
This speeds up pull.without-history ; maybe update and lib.install in very specific situations.

For Cody's situation, this speeds it up from 29s -> 2.6s; still too slow, but much better!

Implementation notes

This changes it so if a branch is already squashed we return it as-is from discardHistory, which avoids memory redundancy and, more importantly, avoids re-hashing the whole subtree which is very expensive on branches with tons of dependencies.

Test coverage

I tested performance on this issue Cody opened:
fixes #5866

Loose ends

Everywhere using discardHistory should maybe just be using squashCausal which can use the squash-result table for caching, but that's all V2 machinery so it may take a bit more finesse to add that; I'll take a look in a separate change.

@ChrisPenner ChrisPenner marked this pull request as ready for review September 9, 2025 21:14
@ChrisPenner
Copy link
Member Author

@aryairani The failing transcripts appear to be also failing on the latest trunk build.

@aryairani aryairani requested a review from Copilot September 10, 2025 12:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the discardHistory function to avoid redundant re-hashing when squashing branches that are already squashed. The main improvement is checking if a branch already has no history before performing expensive squashing operations.

  • Introduces conditional logic to detect already-squashed branches and return them unchanged
  • Adds helper functions that track whether any history was actually discarded to avoid unnecessary work
  • Removes timing wrapper from entity insertion code in sync operations

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
parser-typechecker/src/Unison/Codebase/Branch.hs Core optimization logic with new functions to conditionally discard history and track changes
unison-cli/src/Unison/Share/SyncV2.hs Removes timing wrapper around entity insertion operation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +281 to +286
Causal.One _ _ b0 -> do
let (Any changed, b0') = discardHistory0IfNecessary b0
-- Avoid re-hashing things by returning the original if nothing actually changed
if changed
then (Any True, one b0')
else (Any False, b)
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The do notation on line 281 is unnecessary since this is not a monadic context. Remove the do keyword for cleaner code.

Suggested change
Causal.One _ _ b0 -> do
let (Any changed, b0') = discardHistory0IfNecessary b0
-- Avoid re-hashing things by returning the original if nothing actually changed
if changed
then (Any True, one b0')
else (Any False, b)
Causal.One _ _ b0 ->
let (Any changed, b0') = discardHistory0IfNecessary b0
-- Avoid re-hashing things by returning the original if nothing actually changed
in if changed
then (Any True, one b0')
else (Any False, b)

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

I kind of like do let more than let .. in tbh

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I strongly agree, I add redundant do's all over the place because it prevents reformatting everything when you add another line.

I also despise when a PR review is just a bunch of redundant and inconsequential syntax tweaks someone arbitrarily wants you to do haha. Thanks Copilot...

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed...

Copy link
Contributor

Choose a reason for hiding this comment

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

In the initial comment there's a table with a one-line summary of the changes to each file; that seems potentially useful.

I guess unsurprisingly, you can give the LLM instructions on how to conduct the review, that's cool too, in principle.

@aryairani
Copy link
Contributor

Sorry for using your PR to try out the Copilot review; checking now to see how horrible it may have been

@aryairani aryairani merged commit bd8e315 into trunk Sep 10, 2025
28 of 31 checks passed
@aryairani aryairani deleted the cp/avoid-squash-rehashing branch September 10, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

updating project root stranely slow?

3 participants