A few IO improvements based on suggestions from AI prompts.#924
Merged
A few IO improvements based on suggestions from AI prompts.#924
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets small I/O reductions during import/export by adding caching, removing sync-over-async file reads, and introducing some parallel file loading.
Changes:
- Cache container ancestry lookups during serialization to reduce repeated service calls.
- Make folder key discovery fully async (and deprecate the sync wrapper) to avoid blocking on XML loads.
- Parallelize folder item XML loading during merge, and make import ZIP verification async.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| uSync.Core/Serialization/SyncContainerSerializerBase.cs | Adds an in-memory cache for container chains and clears it alongside the existing folder cache. |
| uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs | Switches folder-key scanning to async, tweaks deleted-item export filtering, and updates logging. |
| uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs | Updates callers to await the new async folder-key API. |
| uSync.BackOffice/Services/SyncFileService.cs | Makes folder verification async and parallelizes XML loads during folder merges. |
| uSync.BackOffice/Services/SyncActionService.cs | Introduces async unzip+verify flow by awaiting folder verification. |
| uSync.BackOffice/Services/ISyncFileService.cs | Adds async verification API and keeps the sync API as an obsolete wrapper. |
| uSync.BackOffice/Services/ISyncActionService.cs | Adds async stream-unpack API and keeps the sync API as an obsolete wrapper. |
Comments suppressed due to low confidence (1)
uSync.BackOffice/Services/SyncActionService.cs:274
UnpackImportFromStreamAsynchas an emptycatch { throw; }block and ends withthrow new Exception("Failed to import")after thefinally. Given thetryblock always returns on success/error and the catch rethrows, the final throw is unreachable and the catch adds no value. Consider removing the catch entirely (or handling/logging), and remove the unreachable throw to simplify control flow.
try
{
_uSyncService.DeCompressFile(stream, tempFolder);
var errors = await _syncFileService.VerifyFolderAsync(tempFolder,
_uSyncConfig.Settings.DefaultExtension);
if (errors.Count > 0)
{
return new UploadImportResult
{
Success = false,
Errors = errors
};
}
_uSyncService.ReplaceFiles(tempFolder, _uSyncConfig.GetWorkingFolder(), true);
return new UploadImportResult
{
Success = true
};
}
catch
{
throw;
}
finally
{
_syncFileService.DeleteFolder(tempFolder);
}
throw new Exception("Failed to import");
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ainersCache type mismatch Agent-Logs-Url: https://github.com/KevinJump/uSync/sessions/1bfc228e-e9a6-4247-a9b2-89154e279425 Co-authored-by: KevinJump <431231+KevinJump@users.noreply.github.com>
…XML loading Agent-Logs-Url: https://github.com/KevinJump/uSync/sessions/408ea6a5-d136-43a2-b422-9855153456da Co-authored-by: KevinJump <431231+KevinJump@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on the prompt "Analyse this code base for any performance improvements, ignore the minor improvements in things like string allocation and concentrate on any potential reduction in database calls or file IO that could be improved upon"
A few different IO things across mainly the root handler, file service, and serializer base. These either reduce some DB calls or some IO file reading, with reductions mainly on content types or datatypes.
Changes Made
SyncContainerSerializerBase): Caches container ancestry as an immutableEntityContainer[]to reduce repeated service calls and prevent accidental cache mutation.SyncHandlerRoot): MadeGetFolderKeysAsyncfully async and replacedList<Guid>withHashSet<Guid>for O(1) deduplication, materializing to a list before caching.SyncFileService): Parallelizes folder item XML loading during merge usingParallel.ForEachAsync, withXmlReaderSettingscloned per call to ensure thread safety.SyncFileService): Made import ZIP verification async to avoid blocking.SyncHandlerRoot): Pass exception object toLogWarningto preserve stack trace and inner-exception details.⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.