Skip to content

Hangs when loading files 12MB or larger in Linux #547

@pdavis68

Description

@pdavis68

I'm using AvaloniaEdit in Linux. When I try to load documents over about 10MB, it simply hangs. A 10MB file will load in well under a second, but the 12MB file I have and any text file larger than that, will cause it to hang.

My code to load the documents is:

    private async Task LoadDocumentAsync(string filePath)
    {
        if (_textEditor == null || _viewModel == null)
        {
            return;
        }

        string fileContent;
        using (var stream = File.OpenRead(filePath))
        {
            // Important: Run the loading on a background thread.
            // The UI thread only handles setting the document once loaded.
            fileContent = await Task.Run(async () =>
            {
                using var reader = new StreamReader(stream);
                return await reader.ReadToEndAsync();
            });
        }

        // Create the TextDocument on the UI thread (required by AvaloniaEdit)
        var loadedDocument = new TextDocument(fileContent);

        // Update the editor document on the UI thread
        _isUpdatingText = true;
        _textEditor.Document = loadedDocument;
        _viewModel.CurrentFilePath = filePath;
        _viewModel.IsDocumentDirty = false;
        _isUpdatingText = false;
    }

I'm under the impression this is preferred to using the .Text property, which suffers from the same issue.

I have a 10MB file it loads in under a second. The next largest text file I have is 12MB and it hangs when I try to load it, or anything larger. I get not exception, I get no warnings, nothing. Just hangs.

I created a very simple test app (this code is from that) that basically has the control in the window with default settings.

Here's my .csproj with the versions I'm using:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="Models\" />
    <AvaloniaResource Include="Assets\**" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Avalonia" Version="11.3.9" />
    <PackageReference Include="Avalonia.Desktop" Version="11.3.9" />
    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.9" />
    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.9" />
    <PackageReference Include="Avalonia.AvaloniaEdit" Version="11.3.0" />
    <PackageReference Include="AvaloniaEdit.TextMate" Version="11.3.0" />
    <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
    <PackageReference Include="Avalonia.Diagnostics" Version="11.3.9">
      <IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
      <PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
  </ItemGroup>
</Project>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions