Skip to content

perf(memory): defer assess_memory_write content to_lowercase until triggers fire #642

Description

@Lang-bt

Problem

memory::policy::assess_memory_write and infer_metadata run on every auto-captured fact and explicit memory_store write. Even for benign household content (User likes hiking, User's name is Jared), they always allocate a full Unicode content.to_lowercase() view before the existing restricted/private/cautious early-outs (#497) can classify the entry.

Most auto-capture writes are allow-path household memories. Paying an unconditional content lowercase allocation on every write is wasted work on Jetson.

Proposed fix

Add ASCII case-insensitive trigger gates over the existing restricted, private-intent, and cautious marker sets (mirroring #608 for extract_facts). Defer content.to_lowercase() until at least one gate fires; use a kind-only metadata fast path for benign content.

Acceptance

  • Byte-identical output on the existing memory_policy_corpus_regression corpus plus mixed-case allow-path cases.
  • policy_bench allow-preference case should show lower per-call latency on Jetson.
  • No behavior change on restricted, private, or cautious hits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceperformance improvement, but not verify on jetson

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions