⚡ Bolt: Optimize file IO using stream reading and early returns#60
⚡ Bolt: Optimize file IO using stream reading and early returns#60google-labs-jules[bot] wants to merge 1 commit into
Conversation
… JSON parsing Replaces `File.ReadAllText().Contains()` and `File.ReadAllBytes()` with lazy evaluations utilizing `File.ReadLines()` and file streams. This ensures file parsing occurs dynamically without fully allocating the memory footprint of the file before search operations.
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
| foreach (var line in File.ReadLines(path)) | ||
| { | ||
| if (line.Contains("<OutputType>Exe</OutputType>", StringComparison.OrdinalIgnoreCase) | ||
| || line.Contains("<OutputType>WinExe</OutputType>", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return true; | ||
| } | ||
| } |
| foreach (var line in File.ReadLines(path)) | ||
| { | ||
| if (line.Contains(value, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return true; | ||
| } | ||
| } |
| foreach (var line in File.ReadLines(path)) | ||
| { | ||
| if (line.Contains(value, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return true; | ||
| } | ||
| } |
💡 What: Replaced occurrences of
File.ReadAllText().Contains()withFile.ReadLines()early exit streams, and updatedWorkspaceLegacyMigration.csto deserialize legacy JSON utilizingFile.OpenReadinstead of allocating byte arrays viaFile.ReadAllBytes.🎯 Why: Reading a full file contents into memory via large string or byte allocations can be highly memory-intensive and is often slow compared to lazy enumeration, especially if only checking for substrings.
📊 Impact: Reduces memory footprint considerably during project classification indexing, workspace setup suggestions, and legacy JSON migrations by stopping file processing immediately on a matched sequence.
🔬 Measurement: Can be verified by running performance profiling around file search operations inside
QuickShell.Core/Services/ProjectClassifier.cs.PR created automatically by Jules for task 7744002579725910642 started by @mta-babel
Summary by cubic
Optimized file I/O by switching to streaming reads and early returns, cutting memory use and speeding up project scanning and legacy workspace migration. Replaced full-file loads with
File.ReadLinesandFile.OpenReadfor JSON..csprojreads to detect<OutputType>; updatedFileContainsto early-exit on match.FileContains.System.Text.Json.pwshinstead ofpowershell.Written for commit 7a4b6fd. Summary will update on new commits.