Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Jan 27, 2025

Description

Improves diff handling and streaming performance in the DiffViewProvider through two main changes:

  1. Enhanced diff algorithm implementation:

    • Replaces simple line comparison with proper diff.diffLines() algorithm
    • Improves EOL character handling and content management
    • Adds detection and handling of auto-formatting changes
    • Better handles edge cases like HTML tag auto-closing
  2. Optimized streaming performance:

    • Implements chunk-based content updates instead of line-by-line
    • Dynamic chunk sizing (max(50, totalLines/20)) for optimal performance
    • Adds 10ms delay between chunks for smooth visualization
    • Improves scroll behavior with smarter viewport management

Type of change

  • New feature
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

The changes have been tested through:

  • Manual verification of diff accuracy with various file types and content changes
  • Performance testing with large files to validate chunk-based streaming
  • Visual testing of streaming animation smoothness
  • Validation of scroll behavior and viewport management

The changes have NOT been tested through:

  • Edge case testing for EOL characters and auto-formatting scenarios

Checklist:

  • [] My code follows the patterns of this project
  • I have performed a self-review of my own code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation

Additional context

This refactor significantly improves the performance and reliability of the diff view streaming functionality, particularly for large files. The chunk-based approach with dynamic sizing ensures smooth visualization while maintaining responsiveness.

Related Issues

Improves performance and reliability for #diff-streaming #large-files

Reviewers

@hannesrudolph


Important

Enhances diff handling and streaming performance in DiffViewProvider.ts with improved diff algorithm and chunk-based updates.

  • Diff Algorithm:
    • Replaces line comparison with diff.diffLines() in scrollToFirstDiff().
    • Handles EOL characters and auto-formatting in saveChanges().
  • Streaming Performance:
    • Implements chunk-based updates in update() with dynamic sizing and 10ms delay.
    • Enhances scroll behavior in scrollEditorToLine() for smoother appearance.
  • Misc:
    • Adds autoFormattingEdits to saveChanges() return value.
    • Adjusts scrollEditorToLine() to scroll only if needed.

This description was created by Ellipsis for 7e64a96. It will automatically update as commits are pushed.

- Replace simple line comparison with proper diff algorithm using diff.diffLines()
  * More accurate diff detection, especially for complex changes like HTML tags
- Improve cursor positioning logic and code clarity
  * Maintain same functional behavior but with clearer intent
- Optimize content update logic
  * Only update changed sections using diff results
  * More efficient updates with less flickering
- Add auto-formatting handling
  * Track preSaveContent and postSaveContent
  * Add autoFormattingEdits to return value
  * Better tracking of editor formatting changes
- Enhance final content handling
  * Improve empty line preservation logic
  * More robust handling of line endings
  * Better preservation of original file formatting
- Extend return value
  * Add autoFormattingEdits field
  * Split content tracking into pre/post save
  * Provide more detailed feedback about changes

Improvements:
- Better performance through targeted updates
- More accurate diff handling
- Enhanced formatting preservation
- Improved auto-formatting tracking
- Increased code clarity and maintainability

Potential impacts to monitor:
- Compatibility with extensions using old return value structure
- Performance with very large files (new diff algorithm)
- Edge cases in empty line preservation
Replace line-by-line diff calculation with optimized chunk-based streaming for better performance with large files. Instead of processing each line individually, content is now updated in dynamic chunks (max(50, totalLines/20)) with a 10ms delay between updates for smooth visualization.

Key improvements:

Replace individual line inserts with efficient bulk content updates
Reduce scroll jitter by only updating viewport when needed
Optimize decoration updates to align with chunk processing
Keep cursor at document start to avoid streaming interference
These changes significantly improve the performance and visual experience of the diff view, particularly when handling larger files or rapid content updates.
@mrubens
Copy link
Collaborator

mrubens commented Jan 28, 2025

Going to close this one for now in favor of #595. Thank you!

@mrubens mrubens closed this Jan 28, 2025
@hannesrudolph hannesrudolph deleted the improve-edit-scrolling branch January 30, 2025 02:50
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.

2 participants