Skip to content

Conversation

@CodeWithBehnam
Copy link
Owner

Summary

  • Add change detection to autosave to avoid redundant localStorage writes
  • Use djb2 hash algorithm for fast, reliable change detection
  • Skip autosave when workflow hasn't been modified

Technical Details

Before

Every 30 seconds, the autosave would:

  1. Serialise the graph (CPU)
  2. Strip large data (CPU)
  3. Write to localStorage (I/O)

Even when nothing changed.

After

Every 30 seconds, the autosave now:

  1. Serialise the graph (CPU)
  2. Strip large data (CPU)
  3. Hash the result (fast, O(n))
  4. Compare with last hash (O(1))
  5. Only write if changed (I/O only when needed)

Hash Algorithm

Uses djb2 (Daniel J. Bernstein) - a simple, fast hash function that's perfect for change detection. It produces a 32-bit unsigned integer from the JSON string.

function hashString(str: string): number {
  let hash = 5381
  for (let i = 0; i < str.length; i++) {
    hash = ((hash << 5) + hash) ^ str.charCodeAt(i)
  }
  return hash >>> 0
}

Test plan

  • bun run typecheck passes
  • bun run lint passes
  • Autosave still works when changes are made
  • No localStorage writes when workflow is unchanged

Behnam Ebrahimi

- Add djb2 hash function for efficient change detection
- Track last saved hash to skip redundant writes
- Create stable JSON (without timestamp) for comparison
- Only update localStorage when data actually changes

This eliminates unnecessary I/O operations when the workflow
hasn't been modified, reducing CPU and storage overhead.

Co-Authored-By: Behnam & Claude Code
@CodeWithBehnam CodeWithBehnam merged commit b33332f into main Dec 25, 2025
2 checks passed
@CodeWithBehnam CodeWithBehnam deleted the perf/autosave-optimization branch December 25, 2025 16:16
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.

2 participants