diffplex icon indicating copy to clipboard operation
diffplex copied to clipboard

Loading of Large File Hangs

Open ajardolino3 opened this issue 3 years ago • 5 comments

I am creating a DiffViewer control (WindowsForms) just like the demo code. Works fine with small files, but when I have a file that has a few thousand lines, it hangs for a while. Eventually it loads, but it just takes forever. Not sure what is wrong. Can this be fixed please?

ajardolino3 avatar May 04 '22 19:05 ajardolino3

Is the delay from the core lib or the UI control?

mmanela avatar May 12 '22 12:05 mmanela

I have the same issue (using DiffPlex.Wpf v1.3.1 in my NET5 winforms application).

The files that I tested were 40k lines of JSON. The loading appears to happen during form.ShowDialog(), and when I try SideBySideDiffBuilder.Diff() it completes pretty much instantly, so it seems to me that the delay is in the UI control. (it also slowly consumes more and more RAM, up to around 2GB before I run out and have to kill the process in task manager)

Looks like the same issue as here: https://github.com/mmanela/diffplex/issues/87

Drake53 avatar Dec 20 '22 15:12 Drake53

i try, WebDiffer is fast, DiffPlex.Wpf is slow , InsertLinesAsync method is slowly , InternalLinesViewer ->StackPanel add
VirtualizingStackPanel.VirtualizationMode="Recycling" VirtualizingStackPanel.IsVirtualizing="True" will not slow when drag,but load file still slow

lanboss avatar Mar 15 '23 02:03 lanboss

i solute the question , changed InsertLinesAsync method private static async Task InsertLinesAsync(Guid guid, InternalLinesViewer panel, List<DiffPiece> lines, bool isOld, UIElement source, int contextLineCount) { // For performance. if (lines == null || panel == null) return; var disablePieces = lines.Count > MaxCount; var i = 100; if (panel.TrackingId != guid) return; InsertLinesInteral(panel, lines.Take(i).ToList(), isOld, source, disablePieces); while (i < lines.Count) { //await Task.Delay(i > 5000 ? 1000 : 800); if (panel.TrackingId != guid) return; await panel.Dispatcher.BeginInvoke(() => { InsertLinesInteral(panel, lines.Skip(i).Take(100).ToList(), isOld, source, disablePieces); }, DispatcherPriority.Background); i += 100; } if (contextLineCount > -1) CollapseUnchangedSections(panel, contextLineCount); } 2 points: 500-> 100 Invoke ->BeginInvoke ,thread level is DispatcherPriority.Background

lanboss avatar Mar 15 '23 09:03 lanboss

    private static async Task InsertLinesAsync(Guid guid, InternalLinesViewer panel, List<DiffPiece> lines, bool isOld, UIElement source, int contextLineCount)
    {   // For performance.
        if (lines == null || panel == null) return;
        var disablePieces = lines.Count > MaxCount;
        var i = 100;
        if (panel.TrackingId != guid) return;
        InsertLinesInteral(panel, lines.Take(i).ToList(), isOld, source, disablePieces);
        while (i < lines.Count)
        {
            //await Task.Delay(i > 5000 ? 1000 : 800);
            if (panel.TrackingId != guid) return;
           await panel.Dispatcher.BeginInvoke(() =>
            {
                InsertLinesInteral(panel, lines.Skip(i).Take(100).ToList(), isOld, source, disablePieces);
            }, DispatcherPriority.Background);
            i += 100;
        }
        if (contextLineCount > -1) CollapseUnchangedSections(panel, contextLineCount);
    }

lanboss avatar Mar 15 '23 09:03 lanboss