It was not required for the correctness of the algorithm.
Details
- Reviewers
durin42 dsp quark - Group Reviewers
hg-reviewers - Commits
- rHG055fee3547df: merge: removed sorting in casefolding detection, for a slight performance win
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
Event Timeline
I think for the correctness of the algorithm sorted() is not needed. However it is there to ensure that the error is deterministic, as iterating over set is in arbitrary order. So running the same merge with multiple case conflicts can potentially lead to two different errors. sorted makes the iteration deterministic. Fujiwara might have more insights.
I am -1 on the patch, and will for the moment request changes unless someone from hg reviewers approves it.
Is it important that the error be deterministic?
I think we can improve the situation if you have exactly two collisions, by sorting (f, foldmap[fold]) and (lastfull, f), but I don't think it can easily be preserved for multiple collisions.
Is it important that the error be deterministic?
Good question. Deterministic error is just to make tests stable AFAIK. If the perf win is noticable, I personally prefer perf win. We can use (glob) and (?) in tests to make it support non-deterministic outputs.
Historically we've biased to keeping merge deterministic so it's easy to reproduce bugs. I'd very much like to keep that property.
Whether or not an error occurs is deterministic, the exact message is the only non-deterministic bit (assuming there's no bugs, heh).
Ah, I see. Alex, do you have any idea what the performance numbers on this are like, anecdotally on your mozilla repo?
Not quite sure this is science, but ....
First set of numbers is tip, second is with my patch:
~/p/mozilla-central ❯❯❯ time ~/projects/hg/hg up consolidate-sandbox-disable; time ~/projects/hg/hg up central 4324 files updated, 0 files merged, 491 files removed, 0 files unresolved (activating bookmark consolidate-sandbox-disable) 9.49 real 10.23 user 3.13 sys 4654 files updated, 0 files merged, 161 files removed, 0 files unresolved (leaving bookmark consolidate-sandbox-disable) 4.74 real 7.59 user 2.73 sys ~/p/mozilla-central ❯❯❯ time ~/projects/hg/hg up consolidate-sandbox-disable; time ~/projects/hg/hg up central 4324 files updated, 0 files merged, 491 files removed, 0 files unresolved (activating bookmark consolidate-sandbox-disable) 4.45 real 7.32 user 2.66 sys 4654 files updated, 0 files merged, 161 files removed, 0 files unresolved (leaving bookmark consolidate-sandbox-disable) 4.83 real 7.50 user 2.66 sys ~/p/mozilla-central ❯❯❯ time ~/projects/hg/hg up consolidate-sandbox-disable; time ~/projects/hg/hg up central 4324 files updated, 0 files merged, 491 files removed, 0 files unresolved (activating bookmark consolidate-sandbox-disable) 4.64 real 7.55 user 2.69 sys 4654 files updated, 0 files merged, 161 files removed, 0 files unresolved (leaving bookmark consolidate-sandbox-disable) 5.09 real 7.87 user 2.67 sys ~/p/mozilla-central ❯❯❯ time ~/projects/hg/hg up consolidate-sandbox-disable; time ~/projects/hg/hg up central 4324 files updated, 0 files merged, 491 files removed, 0 files unresolved (activating bookmark consolidate-sandbox-disable) 5.39 real 8.13 user 2.74 sys 4654 files updated, 0 files merged, 161 files removed, 0 files unresolved (leaving bookmark consolidate-sandbox-disable) 5.27 real 8.00 user 2.70 sys ~/p/mozilla-central ❯❯❯ time ~/projects/hg/hg up consolidate-sandbox-disable; time ~/projects/hg/hg up central 4324 files updated, 0 files merged, 491 files removed, 0 files unresolved (activating bookmark consolidate-sandbox-disable) 4.45 real 7.68 user 2.58 sys 4654 files updated, 0 files merged, 161 files removed, 0 files unresolved (leaving bookmark consolidate-sandbox-disable) 4.93 real 7.72 user 2.61 sys ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ ~/p/mozilla-central ❯❯❯ time ~/projects/hg/hg up consolidate-sandbox-disable; time ~/projects/hg/hg up central 4324 files updated, 0 files merged, 491 files removed, 0 files unresolved (activating bookmark consolidate-sandbox-disable) 4.90 real 6.91 user 2.81 sys 4654 files updated, 0 files merged, 161 files removed, 0 files unresolved (leaving bookmark consolidate-sandbox-disable) 3.99 real 6.81 user 2.52 sys ~/p/mozilla-central ❯❯❯ time ~/projects/hg/hg up consolidate-sandbox-disable; time ~/projects/hg/hg up central 4324 files updated, 0 files merged, 491 files removed, 0 files unresolved (activating bookmark consolidate-sandbox-disable) 4.02 real 7.00 user 2.61 sys 4654 files updated, 0 files merged, 161 files removed, 0 files unresolved (leaving bookmark consolidate-sandbox-disable) 4.82 real 7.42 user 2.69 sys ~/p/mozilla-central ❯❯❯ time ~/projects/hg/hg up consolidate-sandbox-disable; time ~/projects/hg/hg up central 4324 files updated, 0 files merged, 491 files removed, 0 files unresolved (activating bookmark consolidate-sandbox-disable) 4.60 real 7.80 user 2.78 sys 4654 files updated, 0 files merged, 161 files removed, 0 files unresolved (leaving bookmark consolidate-sandbox-disable) 4.11 real 7.77 user 2.73 sys ~/p/mozilla-central ❯❯❯ time ~/projects/hg/hg up consolidate-sandbox-disable; time ~/projects/hg/hg up central 4324 files updated, 0 files merged, 491 files removed, 0 files unresolved (activating bookmark consolidate-sandbox-disable) 4.24 real 7.74 user 2.77 sys 4654 files updated, 0 files merged, 161 files removed, 0 files unresolved (leaving bookmark consolidate-sandbox-disable) 4.35 real 7.80 user 2.78 sys
Going to note that I'm less confident in the correctness of the second change than I am the first.
mercurial/merge.py | ||
---|---|---|
765 | I think you're right, removing the first sorted should be safe though. |
Looks good to me. I'd prefer perf to error message stability. If the latter is a concern, we can re-run the loop if there is at least one case-folding collision detected.
If you want error message stability I'm pretty sure I can get that by changing the error message formatting to be tuple(sorted([f, foldmap[fold])). Let me know if you'd like me to add that.
I think this would be incorrect, since foldprefix is mutated and used in the loop.