From a69e23fb5266dd942d125239e7dcbe8a7c8ab956 Mon Sep 17 00:00:00 2001 From: cirakg Date: Wed, 21 Oct 2026 03:55:01 +0200 Subject: perf(import): keep parsed items packed and the pasted text once A parsed import item with its Entry took about 760 bytes as objects on the Forerunner 255S; packed into one Codec ByteArray it takes about 110, and the importer unpacks one item per store step (wiping the packed secret). Aegis group names are resolved when unpacking, so no step repacks all items. The JSON is parsed from the untrimmed text's bytes and the string is dropped; an incomplete part is saved from those bytes. The form hash is computed before the importer copies the text. The peak of a 100-entry import on the 255S falls from 56 % to 45 %. Co-Authored-By: Claude Opus 5.5 --- source/settings/SettingsJob.mc | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'source/settings') diff --git a/source/settings/SettingsJob.mc b/source/settings/SettingsJob.mc index e6e7bcf..2fc4a3d 100644 --- a/source/settings/SettingsJob.mc +++ b/source/settings/SettingsJob.mc @@ -105,24 +105,31 @@ class SettingsJob extends Jobs.Job { endImport(["Import: waiting import cancelled."] as Array, "Waiting import cancelled", false); return; } - var content = new Forms.Content("import"); - content.add(importMode); - content.add(locked); - var text = ""; - for (var i = 1; i <= IMPORT_TEXT_FIELDS; i++) { - var part = Forms.rawText(_store, "impText" + i); - content.add(part); - text += part; - } - _hash = Forms.hash(_vault, content); + _hash = importHash(importMode, locked); if (Forms.alreadyApplied(_vault, _hash)) { endImport(["Import: already applied. Change the text to import again."] as Array, "Already imported", true); return; } + var text = ""; + for (var i = 1; i <= IMPORT_TEXT_FIELDS; i++) { + text += Forms.rawText(_store, "impText" + i); + } _importStart = System.getTimer(); _importer = new Importer(_vault, text, importMode, locked, _now); } + // The import form's hash. Its own function, so the field bytes it hashes + // are freed before the importer makes its copy of the text. + private function importHash(importMode as Number, locked as Boolean) as String { + var content = new Forms.Content("import"); + content.add(importMode); + content.add(locked); + for (var i = 1; i <= IMPORT_TEXT_FIELDS; i++) { + content.add(Forms.rawText(_store, "impText" + i)); + } + return Forms.hash(_vault, content); + } + private function finishImport(importer as Importer) as Void { _importer = null; var report = importer.report; -- cgit v1.2.3