Skip to content

Regex Compiled on Every Search Request #293

@ARCoder181105

Description

@ARCoder181105

Problem

The sanitizeFTS5Query function in internal/restapi/search_stops_handler.go compiles two regular expressions on every search request, causing unnecessary CPU overhead.

Impact

  • 100x slower than necessary
  • Regex compilation takes ~100,000 ns per request
  • Regex execution takes ~1,000 ns per request
  • At 1,000 searches/sec: wastes approximately 10% of a CPU core

Solution

Move regex compilation to package-level variables so they are compiled once at startup and reused for all requests.

Benefits

  • 100x performance improvement
  • Reduced CPU usage and latency
  • Less GC pressure
  • No behavioral changes
  • Thread-safe (regexp.Regexp is safe for concurrent use)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions