perf(stream): multi-output handles answer with a plain tuple - #762
Merged
Merged
Conversation
SUPERTREND's streaming outputs are outSupertrend/outTrend in the C header. The committed _stream.pxi predates that rename and names them real/integer, so its namedtuple fields disagree with abstract's output_names and test_open_and_fill_matches_batch[SUPERTREND] fails on dev. _ta_lib.c regenerated with Cython 3.2.8, the version that produced the committed file. Claude-Session: https://claude.ai/code/session_01RQsaLFjtMXaVE4UHQKVaeu
update() on a multi-output handle spent ~125 ns/bar in namedtuple.__new__ against a 6 ns C call. MACD update() goes from 182 to 57 ns/bar with every candidate measured in one binary, and from 170 to 37 ns/bar end to end; BBANDS, STOCH, AROON and MINMAXINDEX all land in the -73% to -75% band. The Function API already returns a plain tuple, so the two tiers now agree. tuple -> NamedTuple stays available later as a non-breaking upgrade, since every tuple idiom keeps working; the reverse would not be. Single-output handles are untouched: 178 of 178 single-output classes are byte-identical before and after. test_open_and_fill_matches_batch loses its _fields check and gains a type and arity check that reaches all 23 multi-output and 178 single-output functions; order stays pinned by the element-wise comparison above it. Claude-Session: https://claude.ai/code/session_01RQsaLFjtMXaVE4UHQKVaeu
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.
Multi-output streaming handles now answer with the same plain tuple the Function
API returns, instead of a per-function
NamedTuple. #757 issue examples have been updatedto reflect the new plain tuple API.
Why
update()on a multi-output handle spent ~125 ns/bar insidenamedtuple.__new__, against a 6 ns C call. Measured with every candidatecompiled into one binary and interleaved, so no cross-build layout scatter:
update()returnsNamedTuple(before)tuple.__new__(X_Value, ...)End to end on the real builds: MACD 169.7 -> 36.7 ns/bar, BBANDS -73.4%,
STOCH -73.9%, AROON -74.6%, MINMAXINDEX -74.9%.
open_and_fillis unchangedbeyond noise, correctly: one saved construction against a 700 us call.
Two reasons beyond speed. The Function API already returns a plain tuple, so
the two tiers now agree rather than differing on the same function's outputs.
Scope
23 of 201 functions are multi-output. Single-output handles are untouched
by construction: of the 201 generated stream classes, the 178 single-output
ones are byte-identical before and after, and all 23 changed classes are
multi-output.
What to review
Five hand-written files, 34 insertions and 30 deletions:
tools/generate_stream.py-- four edits: emit(a, b, c)at theupdate/peek/value site and at
open_and_fill; stop emitting the per-functionnamedtuple; stubs emit
Tuple[...]instead of aNamedTupleclasstalib/stream.py-- drop the now-deadX_Valueexport loop; docstringtests/test_stream.py,README.md,CHANGELOGtalib/_stream.pxi,talib/stream.pyiandtalib/_ta_lib.care generated.Testing
1697 passed, on both commits independently.test_open_and_fill_matches_batchloses its_fieldscheck and gains a typeand arity check.