Skip to content

SF-3875 Improve note sync performance - #4003

Open
Nateowami wants to merge 1 commit into
masterfrom
fix/SF-3875-comment-sync-performance
Open

SF-3875 Improve note sync performance#4003
Nateowami wants to merge 1 commit into
masterfrom
fix/SF-3875-comment-sync-performance

Conversation

@Nateowami

@Nateowami Nateowami commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator
  • Performance improvement comes by looking up all note threads in a single pass and placing them in a dictionary
  • Also fixed a bug caused by CommentManager.FindThreads not properly grouping threads with comments on multiple verses

Projects with tons of threads take a long time to sync, and I think it grows with [thread count] * [comments count across all threads]. This results in some very slow syncs that prevent other projects from being able to sync, since we only allow one sync at a time (the worst offender on live spent 17min 18s just on note threads).

The bigger change on the PR is wrapping CommentManager.FindThreads to handle cases where it emits the same thread ID twice, along with a test to demonstrate a) that it does this with certain threads, and b) that the wrapper handles that scenario.


This change is Reviewable

@Nateowami Nateowami added will require testing PR should not be merged until testers confirm testing is complete e2e Run e2e tests for this pull request labels Jul 24, 2026
@Nateowami
Nateowami temporarily deployed to screenshot_diff July 24, 2026 22:52 — with GitHub Actions Inactive
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.13%. Comparing base (1a2130a) to head (192df5a).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...c/SIL.XForge.Scripture/Services/ParatextService.cs 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4003   +/-   ##
=======================================
  Coverage   81.12%   81.13%           
=======================================
  Files         659      660    +1     
  Lines       42631    42649   +18     
  Branches     6993     6992    -1     
=======================================
+ Hits        34584    34602   +18     
+ Misses       6908     6895   -13     
- Partials     1139     1152   +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@pmachapman pmachapman self-assigned this Jul 28, 2026
@pmachapman
pmachapman self-requested a review July 28, 2026 01:11

@pmachapman pmachapman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@Nateowami Has this bug been reported to the Paratext team? I can't actually think of a way of fixing the bug within Comment.CompareTo(), as it seems a grouping (which your code does) is needed to fix the sorting.

@pmachapman reviewed 4 files and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on Nateowami).


src/SIL.XForge.Scripture/Services/CommentManagerExtensions.cs line 41 at r1 (raw file):

                threads.Add(thread);
            }
        }

We could speed this up by iterating over manager.AllComments, then building the CommentThreads from there. In particular, we would group then sort the comments correctly via our own version of the logic in CommentManager.SortAndGroupThreads.

I'm not making this blocking, as I am interested in your thoughts, although perhaps I lean towards us implementing our own iterator as the PT CommentManager.FindThreads() code has not changed in years?

Code quote:

        foreach (CommentThread thread in manager.FindThreads())
        {
            if (threadIndexById.TryGetValue(thread.Id, out int index))
                threads[index] = manager.FindThread(thread.Id);
            else
            {
                threadIndexById[thread.Id] = threads.Count;
                threads.Add(thread);
            }
        }

- Performance improvement comes by looking up all note threads in a
single pass and placing them in a dictionary
- Also fixed a bug caused by CommentManager.FindThreads not properly
grouping threads with comments on multiple verses.
@Nateowami
Nateowami force-pushed the fix/SF-3875-comment-sync-performance branch from 192df5a to f244bc6 Compare August 6, 2026 18:31

@Nateowami Nateowami left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@Nateowami made 1 comment and resolved 1 discussion.
Reviewable status: 2 of 4 files reviewed, all discussions resolved (waiting on pmachapman).


src/SIL.XForge.Scripture/Services/CommentManagerExtensions.cs line 41 at r1 (raw file):

Previously, pmachapman (Peter Chapman) wrote…

We could speed this up by iterating over manager.AllComments, then building the CommentThreads from there. In particular, we would group then sort the comments correctly via our own version of the logic in CommentManager.SortAndGroupThreads.

I'm not making this blocking, as I am interested in your thoughts, although perhaps I lean towards us implementing our own iterator as the PT CommentManager.FindThreads() code has not changed in years?

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e Run e2e tests for this pull request will require testing PR should not be merged until testers confirm testing is complete

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants