Skip to content

Index FETCH fields in a single pass - #207

Merged
stevebauman merged 1 commit into
masterfrom
fix/index-fetch-fields
Nov 16, 2026
Merged

stevebauman merged 1 commit into
masterfrom
fix/index-fetch-fields

Conversation

@stevebauman

Copy link
Copy Markdown
Member

Creating messages from FETCH responses currently scans each response six times to find its UID, size, flags, headers, body, and body structure. Each lookup converts the tokens it passes to strings, which can repeatedly rebuild large body strings and nested lists.

This indexes field names and BODY sections in a single pass, then reads the required fields from that index. Literal contents and nested lists are skipped during indexing. Duplicate fields continue to use the first occurrence, and missing fields retain their existing defaults.

The following benchmarks compare this change against the implementation after #206 on PHP 8.4.27, with CLI OPcache and JIT disabled. Each value is the median of six alternating samples, with each sample averaging 20 executions after a warm-up.

Workload Messages Before CPU time After CPU time CPU time reduction
Metadata 35,798 102.8 ms 56.6 ms 45.0%
4 KiB bodies 5,000 21.2 ms 11.1 ms 47.6%
256 KiB bodies, UID first 500 5.0 ms 1.1 ms 78.8%
256 KiB bodies, UID last 500 15.5 ms 1.1 ms 93.1%

These measurements exercise get() with prepared SEARCH and FETCH responses, covering local UID processing, field extraction, and message construction. Response parsing, network time, and the connection's FETCH-response filtering are excluded. Every sample verified the returned message count, UIDs, flags, sizes, headers, and bodies.

All 1,046 unit tests pass.

Refs #200.

@stevebauman
stevebauman merged commit 136f415 into master Nov 16, 2026
13 checks passed
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