xvp
ScribblingsArticles02 / Thinking

Importing Apple Journal: When More Scans Run Faster

Moving years of Apple Journal entries between iCloud accounts, and why fewer interpreted loops mattered more than fewer file scans.

On this page

Moving my journal to a different iCloud account sounded like a small administrative job. It turned into a migration shortcut—and a useful reminder that the cost of an operation depends on where it runs.

An export without an import

Apple Journal has a handy export feature, but no import feature. Unfortunately for me, I needed to move years of journal entries across iCloud accounts.

Apple gives you an export with all your journal entries as HTML files, which reference specific UUIDed attachments that live in a separate, unified “Resources” folder. But there’s no neat way to put that data back into Journal.

Luckily, we have Apple Shortcuts.

I made a shortcut that parses each exported HTML entry, regex-extracts the title, body and date, identifies its attachments from their UUIDs, finds the corresponding resource files, and recreates the entry in Journal.

The expensive loop

During development, I found an interesting little CS problem.

Initially, my shortcut looped through 1,000+ exported resource files for every journal entry, checking whether each file belonged to that entry. It worked, but Shortcuts loops are incredibly slow—like really, really slow.

Counterintuitively, the faster way to match the attachments was to extract the handful of attachment UUIDs first, loop over those, then use the native “Filter Files” operation across all 1,000+ resources to return the single matching resource.

Algorithmically, this seems slower, but the important difference is where the loop runs. Shortcuts only has to interpret up to 13 iterations—the maximum number of attachments in Journal—while the thousands of comparisons happen inside Apple’s much faster native filtering code. In practice, minimizing expensive interpreted Shortcuts iterations mattered far more than minimizing the number of cheap native operations.

The two approaches, in pseudocode

These sketches show the attachment-matching step. Both versions parse the same HTML and recreate the entry with its original title, body, date, and matched attachments.

First version: interpret a loop over every resource

text
allResources = filesIn("Resources")

FOR EACH htmlFile IN exportedEntries:
    entry = parseHTML(htmlFile)
    attachmentIDs = extractAttachmentUUIDs(entry)
    attachments = []

    # 1,000+ interpreted Shortcuts iterations per entry
    FOR EACH resource IN allResources:
        IF resourceNameMatchesAnyUUID(resource, attachmentIDs):
            attachments.append(resource)

    createJournalEntry(
        title = entry.title,
        body = entry.body,
        date = entry.date,
        attachments = attachments
    )

Faster version: interpret only the attachment loop

text
allResources = filesIn("Resources")

FOR EACH htmlFile IN exportedEntries:
    entry = parseHTML(htmlFile)
    attachmentIDs = extractAttachmentUUIDs(entry)
    attachments = []

    # At most 13 interpreted Shortcuts iterations per entry
    FOR EACH uuid IN attachmentIDs:
        # The scan happens inside Apple's native Filter Files action
        matches = FILTER_FILES(allResources, name CONTAINS uuid)

        IF matches IS NOT EMPTY:
            attachments.append(FIRST(matches))

    createJournalEntry(
        title = entry.title,
        body = entry.body,
        date = entry.date,
        attachments = attachments
    )

The second version still searches the resources. It may make several native passes instead of one explicit pass, but it avoids asking Shortcuts to interpret thousands of individual loop iterations.

With the attachment count bounded at 13, repeated linear scans are still linear in the resource count when that bound is treated as a constant. The practical win came from the execution cost hidden inside each step, rather than a better asymptotic bound.

An interesting case where Big-O isn’t the whole performance story.

Thanks for following along.

Back to the notebook