Skip to content

Avoid repeated array merges in prompt formatting - #650

Open
andreybolonin wants to merge 1 commit into
modelcontextprotocol:mainfrom
andreybolonin:perf/prompt-formatter-append
Open

andreybolonin wants to merge 1 commit into
modelcontextprotocol:mainfrom
andreybolonin:perf/prompt-formatter-append

Conversation

@andreybolonin

Copy link
Copy Markdown

Mixed prompt results repeatedly copy a growing message array through array_merge. Append each formatted message directly while preserving numeric-key reindexing and string-key replacement. A unit test covers nested keys, order, and object identity.

Local PHP 8.5 benchmark (500 items, 100 iterations): 65.6 → 28.2 ms, with lower peak additional memory (136.9 → 124.6 KB). This measures the affected operation, not full request latency.

Validation: make ci (Composer update, PHP CS Fixer, PHPStan, PHPUnit).

This branch has not been deployed

No deployments
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