Skip to content

A few IO improvements based on suggestions from AI prompts.#924

Merged
KevinJump merged 5 commits intov17/mainfrom
v17/ai-performance
Apr 7, 2026
Merged

A few IO improvements based on suggestions from AI prompts.#924
KevinJump merged 5 commits intov17/mainfrom
v17/ai-performance

Conversation

@KevinJump
Copy link
Copy Markdown
Owner

@KevinJump KevinJump commented Mar 26, 2026

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

  • Cache container ancestry lookups (SyncContainerSerializerBase): Caches container ancestry as an immutable EntityContainer[] to reduce repeated service calls and prevent accidental cache mutation.
  • Async folder key discovery (SyncHandlerRoot): Made GetFolderKeysAsync fully async and replaced List<Guid> with HashSet<Guid> for O(1) deduplication, materializing to a list before caching.
  • Parallel folder item loading (SyncFileService): Parallelizes folder item XML loading during merge using Parallel.ForEachAsync, with XmlReaderSettings cloned per call to ensure thread safety.
  • Async ZIP import verification (SyncFileService): Made import ZIP verification async to avoid blocking.
  • Improved exception logging (SyncHandlerRoot): Pass exception object to LogWarning to 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • UnpackImportFromStreamAsync has an empty catch { throw; } block and ends with throw new Exception("Failed to import") after the finally. Given the try block 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.

Comment thread uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Comment thread uSync.Core/Serialization/SyncContainerSerializerBase.cs Outdated
Comment thread uSync.BackOffice/Services/SyncFileService.cs
Comment thread uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs Outdated
KevinJump and others added 3 commits March 27, 2026 13:47
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>
@KevinJump KevinJump merged commit 7401771 into v17/main Apr 7, 2026
4 checks passed
@KevinJump KevinJump deleted the v17/ai-performance branch April 7, 2026 09:24
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.

3 participants