Skip to content

⚡ Replace File.Create with async FileStream for SettingsManager - #151

Open
Avicennasis wants to merge 1 commit into
mainfrom
perf-async-filestream-7371063026629044736
Open

⚡ Replace File.Create with async FileStream for SettingsManager#151
Avicennasis wants to merge 1 commit into
mainfrom
perf-async-filestream-7371063026629044736

Conversation

@Avicennasis

Copy link
Copy Markdown
Owner

💡 What: Replaced the synchronous File.Create(tempPath) call in SettingsManager.SaveSettingsAsync with new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous).

🎯 Why: The previous implementation used File.Create, which performs synchronous I/O at the OS level and blocks thread-pool threads when used with JsonSerializer.SerializeAsync. This caused unnecessary CPU blocking during the file save operation, hindering overall application performance. Using FileOptions.Asynchronous ensures that the subsequent await JsonSerializer.SerializeAsync call utilizes true asynchronous I/O, freeing up threads while the disk write completes.

📊 Measured Improvement:
Note: Due to the WPF target framework requirement (net8.0-windows), BenchmarkDotNet could not execute a baseline measurement successfully within the Linux testing environment, as the necessary runtime framework was unavailable.

Despite the lack of hard metric numbers, replacing blocking I/O with true asynchronous I/O in file writing operations inside an async context is an established architectural optimization in .NET. It prevents thread-pool starvation, reduces CPU context switches, and ensures that the UI/background threads remain highly responsive during serialization and disk write phases.


PR created automatically by Jules for task 7371063026629044736 started by @Avicennasis

@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant