From e0ff8a56b58d61dc70d008d0df57978ec37ad391 Mon Sep 17 00:00:00 2001 From: onevcat Date: Thu, 18 Jun 2026 23:16:15 +0900 Subject: [PATCH] Avoid full workspace JSON decode in persistence normalizer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RepositoryEntryNormalizer.normalize called ProjectWorkspace.load for every persisted entry to check if it should force kind to .plain. This performed synchronous Data(contentsOf:) + JSONDecoder.decode per entry on every save — wasteful when most entries are not workspaces. Replace with ProjectWorkspace.hasMetadata, a lightweight FileManager.fileExists check that only does a stat syscall. --- supacode/Domain/ProjectWorkspace.swift | 4 ++++ .../Settings/BusinessLogic/RepositoryPersistenceKeys.swift | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/supacode/Domain/ProjectWorkspace.swift b/supacode/Domain/ProjectWorkspace.swift index c33b3bd1..eda211fc 100644 --- a/supacode/Domain/ProjectWorkspace.swift +++ b/supacode/Domain/ProjectWorkspace.swift @@ -434,6 +434,10 @@ nonisolated struct ProjectWorkspace: Codable, Equatable, Hashable, Sendable { .appending(path: metadataFileName) } + static func hasMetadata(at rootURL: URL) -> Bool { + FileManager.default.fileExists(atPath: metadataURL(for: rootURL).path(percentEncoded: false)) + } + static func load(from rootURL: URL) -> ProjectWorkspace? { let metadataURL = metadataURL(for: rootURL) guard let data = try? Data(contentsOf: metadataURL) else { diff --git a/supacode/Features/Settings/BusinessLogic/RepositoryPersistenceKeys.swift b/supacode/Features/Settings/BusinessLogic/RepositoryPersistenceKeys.swift index 75bb222d..a90f67ee 100644 --- a/supacode/Features/Settings/BusinessLogic/RepositoryPersistenceKeys.swift +++ b/supacode/Features/Settings/BusinessLogic/RepositoryPersistenceKeys.swift @@ -205,7 +205,7 @@ nonisolated enum RepositoryEntryNormalizer { return order.compactMap { path in guard let kind = kindByPath[path] else { return nil } - if ProjectWorkspace.load(from: URL(fileURLWithPath: path)) != nil { + if ProjectWorkspace.hasMetadata(at: URL(fileURLWithPath: path)) { return PersistedRepositoryEntry(path: path, kind: .plain) } return PersistedRepositoryEntry(path: path, kind: kind) -- 2.51.2