<feed xmlns='http://www.w3.org/2005/Atom'>
<title>dotemacs/modules/org-refile-config.el, branch performance</title>
<subtitle>My Emacs configuration
</subtitle>
<id>https://git.cjennings.net/dotemacs/atom?h=performance</id>
<link rel='self' href='https://git.cjennings.net/dotemacs/atom?h=performance'/>
<link rel='alternate' type='text/html' href='https://git.cjennings.net/dotemacs/'/>
<updated>2025-11-12T00:34:08+00:00</updated>
<entry>
<title>perf: Optimize org-refile with caching to eliminate 15-20s delay</title>
<updated>2025-11-12T00:34:08+00:00</updated>
<author>
<name>Craig Jennings</name>
<email>c@cjennings.net</email>
</author>
<published>2025-11-12T00:34:08+00:00</published>
<link rel='alternate' type='text/html' href='https://git.cjennings.net/dotemacs/commit/?id=22e359cc511e4a3ee8a93164e299d62a40cd52f7'/>
<id>urn:sha1:22e359cc511e4a3ee8a93164e299d62a40cd52f7</id>
<content type='text'>
Implemented comprehensive caching solution for org-refile targets that
eliminates repeated filesystem scans (34,649 files) on every refile operation.

Performance Impact:
- Before: 15-20 seconds per refile × 12+/day = 3-4 minutes daily
- After: Instant (&lt;50ms) via cache, async build in background
- Daily time saved: ~3-4 minutes + eliminated 12+ context switches

Root Cause:
- cj/build-org-refile-targets scanned all files in 3 directories:
  * ~/.emacs.d (11,995 files)
  * ~/code (18,695 files)
  * ~/projects (3,959 files)
- Called on EVERY refile via cj/org-refile
- directory-files-recursively is expensive with deep hierarchies

Solution Implemented:
1. Cache layer with 1-hour TTL
   - First call: builds and caches targets (one-time cost)
   - Subsequent calls: use cache (instant)
   - Auto-refresh after 1 hour or Emacs restart

2. Async cache building
   - Runs 5 seconds after Emacs idle (non-blocking)
   - Zero startup impact
   - Cache ready before first use in typical workflow

3. Manual refresh available
   - M-x cj/org-refile-refresh-targets
   - Use after adding new projects/todo.org files
   - Force rebuild bypasses cache

4. Robust error handling
   - Building flag prevents concurrent builds
   - unwind-protect ensures flag always clears
   - Graceful handling if user refiles before async build completes

Changes:
- modules/org-refile-config.el:
  * Added cache variables with TTL support
  * Modified cj/build-org-refile-targets for caching
  * Added cj/org-refile-refresh-targets for manual refresh
  * Async build via run-with-idle-timer
  * Enhanced commentary documenting performance

- tests/test-org-refile-build-targets.el (NEW):
  * 9 comprehensive ERT tests
  * Coverage: normal, boundary, error cases
  * Tests cache logic, TTL, force rebuild, async flag
  * All tests pass, zero regressions

Test Results:
- 9/9 new tests passing
- 1,814 existing tests still passing
- Zero regressions introduced
</content>
</entry>
<entry>
<title>changing repositories</title>
<updated>2025-10-12T16:47:26+00:00</updated>
<author>
<name>Craig Jennings</name>
<email>c@cjennings.net</email>
</author>
<published>2025-10-12T16:47:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.cjennings.net/dotemacs/commit/?id=092304d9e0ccc37cc0ddaa9b136457e56a1cac20'/>
<id>urn:sha1:092304d9e0ccc37cc0ddaa9b136457e56a1cac20</id>
<content type='text'>
</content>
</entry>
</feed>
