Skip to content

perf: cache compiled regex patterns#143

Merged
jdx merged 1 commit intomainfrom
perf/cache-compiled-regex
Jan 19, 2026
Merged

perf: cache compiled regex patterns#143
jdx merged 1 commit intomainfrom
perf/cache-compiled-regex

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Jan 19, 2026

Summary

  • Cache compiled regex patterns to avoid recompilation on daemon restarts

Problem

Every time a daemon starts, its ready_output regex pattern is recompiled. For daemons that restart frequently (due to crashes, retries, or normal operation), this is wasteful since the pattern doesn't change.

Solution

  • Add a global REGEX_CACHE HashMap that stores compiled patterns keyed by their pattern string
  • Add get_or_compile_regex() helper that returns cached regex or compiles and caches a new one
  • Update the daemon startup code to use the cached regex

The cache is thread-safe using std::sync::Mutex and persists for the lifetime of the supervisor process.

Test plan

  • cargo build passes
  • Manual test with daemon that uses ready_output

🤖 Generated with Claude Code


Note

Improves daemon startup performance by reusing compiled regexes for readiness detection.

  • Adds global REGEX_CACHE and get_or_compile_regex() in supervisor.rs to cache compiled regex::Regex by pattern
  • Updates readiness logic to use cached regex for ready_output instead of recompiling each time
  • Minor lockfile change (Cargo.lock) including a new libc entry

Written by Cursor Bugbot for commit 66942f5. This will update automatically on new commits. Configure here.

Add a global cache for compiled regex patterns to avoid recompiling
the same pattern on each daemon restart. This is particularly helpful
for daemons that restart frequently with the same ready_output pattern.

- Add REGEX_CACHE static HashMap for storing compiled patterns
- Add get_or_compile_regex() helper that uses cache-or-compile pattern
- Update ready_output pattern handling to use cached regex

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jdx jdx merged commit c22b1d3 into main Jan 19, 2026
4 checks passed
@jdx jdx deleted the perf/cache-compiled-regex branch January 19, 2026 03:42
@jdx jdx mentioned this pull request Jan 19, 2026
jdx added a commit that referenced this pull request Jan 19, 2026
## 🤖 New release

* `pitchfork-cli`: 0.3.0 -> 0.3.1

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.3.1](v0.3.0...v0.3.1) -
2026-01-19

### Added

- implement daemon dependency resolution
([#135](#135))
- add restart command to CLI
([#134](#134))

### Fixed

- restart command preserves daemon dependency configuration
([#142](#142))
- add missing depends field to restart command
([#136](#136))
- set IPC socket permissions to 0600 for security
([#133](#133))
- handle shell command parsing errors instead of silently failing
([#132](#132))

### Other

- reduce unnecessary daemon cloning in loops
([#144](#144))
- use periodic log flushing instead of per-line
([#139](#139))
- refresh only tracked PIDs instead of all processes
([#141](#141))
- cache compiled regex patterns
([#143](#143))

### Security

- add rate limiting to IPC server
([#137](#137))
- canonicalize config paths to prevent symlink exploitation
([#138](#138))
- add centralized daemon ID validation
([#140](#140))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Prepares the 0.3.1 release and updates metadata/documentation
accordingly.
> 
> - **Changelog**: Adds `0.3.1` entry detailing added dependency
resolution, new `restart` command, fixes, performance tweaks, and
security hardening
> - **Version bumps**: Updates `version` to `0.3.1` in `Cargo.toml`,
`Cargo.lock`, `docs/cli/commands.json`, `docs/cli/index.md`, and
`pitchfork.usage.kdl`
> - **Docs regen**: Refreshes CLI docs/spec to reflect the new version
(no behavioral changes in this diff)
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9f9d386. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@jdx jdx mentioned this pull request Jan 19, 2026
jdx added a commit that referenced this pull request Jan 19, 2026
## 🤖 New release

* `pitchfork-cli`: 1.0.0

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [1.0.0](https://github.com/jdx/pitchfork/releases/tag/v1.0.0) -
2026-01-19

### Added

- implement daemon dependency resolution
([#135](#135))
- add restart command to CLI
([#134](#134))

### Fixed

- restart command preserves daemon dependency configuration
([#142](#142))
- add missing depends field to restart command
([#136](#136))
- set IPC socket permissions to 0600 for security
([#133](#133))
- handle shell command parsing errors instead of silently failing
([#132](#132))

### Other

- bump version to 1.0.0
([#147](#147))
- release v0.3.1 ([#121](#121))
- reduce unnecessary daemon cloning in loops
([#144](#144))
- use periodic log flushing instead of per-line
([#139](#139))
- refresh only tracked PIDs instead of all processes
([#141](#141))
- cache compiled regex patterns
([#143](#143))

### Security

- add rate limiting to IPC server
([#137](#137))
- canonicalize config paths to prevent symlink exploitation
([#138](#138))
- add centralized daemon ID validation
([#140](#140))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Prepares the 1.0.0 release and updates `CHANGELOG.md` with the
finalized notes.
> 
> - Adds `1.0.0` section: daemon dependency resolution, new CLI
`restart` command, fixes for dependency preservation and shell parsing,
secure IPC socket perms, plus performance/maintenance updates
> - Documents security hardening: IPC rate limiting, config path
canonicalization, centralized daemon ID validation
> - Retains prior `0.3.1` notes for historical context
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
4182984. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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.

1 participant