Repository navigation
perf: cache compiled chat templates - #1518
Merged
Merged
Conversation
Cache the MiniJinja environment on ChatTemplateProcessor so typed, raw, history and probe renders reuse the same compiled template across the processor lifetime instead of rebuilding filters and bytecode on each call. Keep per-request messages, tools and kwargs outside the cache, cache immutable parse failures, and preserve the TemplateRejection sentinel/fallback split added for template-side request rejections. Refs #1235
inureyes
added a commit
that referenced
this pull request
Aug 30, 2026
## Summary - Add approximate retained-byte budgets to the in-memory `/v1/responses` response store and conversation transcript store, with checked/saturating accounting and running totals. - Replace per-eviction linear victim scans with a `BTreeSet` LRU index so live entries keep one bounded metadata node and eviction removes the oldest entry in O(log n). - Expose `--responses-store-max-bytes` / `MLXCEL_RESPONSES_STORE_MAX_BYTES` and `--conversation-store-max-bytes` / `MLXCEL_CONVERSATION_STORE_MAX_BYTES` on both server entry points, then document the knobs. - Preserve the runtime-settings work merged by PR #1516 (`01c20350`) while rebasing onto main through PR #1518 (`972b5f3a`, chat-template-cache head); the only conflict was the colocated `mlxcel-server` test block, and both settings tests plus byte-budget tests are retained. ## Validation - PASS: `cargo test --lib responses_store -- --nocapture` (16 tests; byte-only eviction, count+byte pressure, oversized single entry, exact boundary, replacement, access-order refresh, TTL, zero/extreme budgets, running total) - PASS: `cargo test --lib conversation_store -- --nocapture` (13 tests; byte-only eviction, count+byte pressure, oversized single transcript, exact boundary, update/replacement, access-order refresh, TTL, zero/extreme budgets, running total) - PASS: `cargo test --lib store_byte_budgets_round_trip_through_into_startup_config -- --nocapture` - PASS: `cargo test --bin mlxcel serve_store_byte_budget -- --nocapture` - PASS: `cargo test --bin mlxcel-server store_byte_budget -- --nocapture` - PASS: `cargo test --bin mlxcel-server settings_cli_mlxcel_server -- --nocapture` (preserved runtime-settings PR #1516 while rebasing onto main through PR #1518) - PASS: `cargo test --bin mlxcel settings_cli_mlxcel_serve -- --nocapture` (preserved runtime-settings PR #1516 while rebasing onto main through PR #1518) - PASS: `cargo test --bin mlxcel settings_cli_build_startup_input_defaults_off_and_propagates_enablement -- --nocapture` (preserved runtime-settings PR #1516 while rebasing onto main through PR #1518) - PASS: `cargo test --lib settings_cli -- --nocapture` (preserved runtime-settings PR #1516 while rebasing onto main through PR #1518) - PASS: `cargo test --test llama_compat_manifest manifest_option_claims_hold_on_both_server_binaries -- --nocapture` - PASS: `python3 scripts/ci/check_llama_compat_manifest.py` - PASS: `cargo fmt --all --check` - PASS: `cargo clippy --lib --bin mlxcel --bin mlxcel-server -- -D warnings` - PASS: `git diff --check` - PASS: static scan found no conflict markers or old `min_by` / `min_by_key` / `evict_to_capacity` victim-scan code in the touched stores. ## Hosted Checks - PASS: cargo-clippy, cargo-deny, cargo-fmt, OpenXLA feature compile, Detect changes, crate versions, cross-repo refs, kernel dtype keys, license/cla, llama-compat manifest. - SKIP: MLX pin extraction and OpenXLA feature link were skipped by workflow conditions. ## Technical Reports - `TECHNICAL_REPORTS/1519-store-byte-bounds-20260830.en.md` - `TECHNICAL_REPORTS/1519-store-byte-bounds-20260830.ko.md` ## Limits - These validations are deterministic unit/config/static checks. I did not run broad workspace tests, cold release builds, real model checkpoints, ffmpeg, or hardware qualification for this server-memory accounting change. Closes #1248
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validation
Reports
Closes #1235