Precompute fast-path eligibility for gang processing#576
Open
chall37 wants to merge 3 commits into
Open
Conversation
Replace the 11-condition runtime check in terminalAppendMixedAsciiGang: with a precomputed _fastPathEligible ivar that is recomputed at each state-mutation point. The hot path is now one ivar read plus two lightweight checks (tokens.count and grid canTakeFastPath). Add terminalActiveCharsetDidChangeTo: delegate callback so charset changes (SI/SO) can invalidate the cache. Include a debug assertion that validates the cached value against a fresh computation on every call.
Address three cache invalidation bugs in the precomputed _fastPathEligible boolean: - Recompute after evaluateTriggers: block executes (expectations can be consumed by matching during trigger evaluation) - Recompute after updateExpectFrom: updates expectations - Recompute after setTerminalEnabled: assigns terminal modes during session startup/revive Add self-healing recompute at the top of terminalAppendMixedAsciiGang: for lazy expectation deadline expiry (deadlines pass without notification, so the cache cannot be eagerly invalidated). Add mutation-queue-only annotations to _computeFastPathEligible and _recomputeFastPathEligible. Add 14 new tests covering every _fastPathEligible condition: insert mode, wraparound, ANSI mode, alt buffer, command start coord, line drawing mode, logging, publishing, expectations, print buffer, multiple simultaneous conditions, expectation consumed by match, expectation expired by deadline, and post-trigger action drain transitions.
Add testGang_fastPathPerformance (cached boolean gang path) and testGang_charAtATimePerformance (character-at-a-time baseline) using XCTest measure blocks. 100 gang calls of 100 lines each per iteration.
Owner
|
I'm not sure the juice is worth the squeeze. After running it in an optimized build, I get: I've pushed my changes to the fastpath-perf branch so you can see what I did. That being said, I do plan to merge the performance tests because it's awesome to have performance tests. |
Contributor
Author
|
Ah, I must have been benching the debug build! If the gains seem too good to be true... |
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
10 XCTest measure iterations x100 gang calls of 100 lines (10,000 lines per iteration, 1,000,000 lines total per test).