Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Performance tuning (stream + incr experiments) #1230

Merged
merged 46 commits into from
Oct 27, 2024

Conversation

DaveSkender
Copy link
Owner

@DaveSkender DaveSkender commented Jul 29, 2024

Side piece of

@DaveSkender DaveSkender added this to the v3 milestone Jul 29, 2024
@DaveSkender DaveSkender changed the base branch from main to v3-increments July 29, 2024 00:36
@DaveSkender DaveSkender self-assigned this Jul 29, 2024
@DaveSkender
Copy link
Owner Author

Starting point:

Method Mean Error StdDev
AdlHub 30.87 us 5.544 us 0.304 us
AtrHub 45.33 us 20.505 us 1.124 us
AtrStopHub 97.21 us 18.485 us 1.013 us
AlligatorHub 50.89 us 16.643 us 0.912 us
EmaHub 26.27 us 8.360 us 0.458 us
QuoteHub 13.02 us 1.225 us 0.067 us
QuotePartHub 29.28 us 22.817 us 1.251 us
RenkoHub 159.02 us 18.238 us 1.000 us
SmaHub 36.62 us 9.782 us 0.536 us
TrHub 35.04 us 9.639 us 0.528 us

@DaveSkender
Copy link
Owner Author

Method Mean Error StdDev
AtrHub 45.73 us 1.910 us 0.105 us
AtrStopHub 72.14 us 4.821 us 0.264 us
TrHub 35.92 us 5.774 us 0.316 us

@DaveSkender
Copy link
Owner Author

DaveSkender commented Jul 29, 2024

  • Compare GetAlligator() to main, possibly regressed perf test
  • Compare difference between EMA and TR, TR should about the same
  • Try rolling buffer for series, possibly a resetting variant for hubs, notably for SMA-types
  • Compare without Reusable base class, or just as abstract.

@DaveSkender
Copy link
Owner Author

DaveSkender commented Jul 29, 2024

New incremental “buffered” list types

Method Mean Error StdDev
EmaListQ 7.194 us 0.0750 us 0.0664 us
EmaListP 6.634 us 0.0737 us 0.0653 us
EmaArray 5.206 us 0.0999 us 0.0934 us
EmaSeries 8.430 us 0.0891 us 0.0834 us

@DaveSkender
Copy link
Owner Author

DaveSkender commented Jul 30, 2024

This is a better equivalence test for incremental "buffer" methods for EMA.
Static series are still the most performant overall.
The "Inc" methods are only faster than the original because we're not sorting the input, but are equivalently 4× slower, likely due to re-writes from the RemoveAt(0) buffer management.

Method Mean Ratio Notes
IncRus 7.35us 2.60 Incrementing with IReusable input value, one at a time.
IncRusBatch 7.27us 2.58 Incrementing with IReusable batch.
IncQot 7.42us 2.63 Incrementing with IQuote input value, one at a time.
IncQotBatch 7.29us 2.58 Incrementing with IQuote batch.
IncPrm 5.15us 1.83 Incrementing with primitive double, one at a time.
IncPrmBatch 5.27us 1.87 Incrementing with primitive double batch.
SeriesEqiv 2.82us 1.00 Original series without sorting (benchmark).
SeriesOrig 8.57us 3.04 Original series with sorting.
IncremEqiv 13.06us 4.63 Incrementing with Quote batch and sorting, for a same-same comparison.
StreamEqiv 27.32us 9.67 Stream hub. It has more self-healing and analysis features (more overhead).

Still need to fix/try out a few scenarios:

  • Add argument null checks
  • Try Add overload syntax again; this was conflicting with base List.Add(double?).
  • Try rename class to "Ema" again, there were some conflicts with utilities.
  • Add buffer to original series, just for a sanity check
  • Explore alternatives to RemoveAt(0) for incrementing buffer.
  • Consider removing primitive variant since it's an old model, like TA-LIB, that just offloads work to the user. Or, defer to the backlog.

Also, given the 3× improvement without sorting:

  • Consider offloading sorting responsibility for time-series methods to the user. I suspect most batch quote providers will or can be fetched in a correct sort anyway.
    • Related: consider using IReadOnlyList<IQuote> quotes as input, instead of IEnumerable<IQuote> quotes
    • Update documentation accordingly
  • Expand Validate() to have generic overload (related)?

Increment variants deferred to:

@DaveSkender DaveSkender changed the title test: Performance tuning (stream hubs) test: Performance tuning (stream hubs, increment experiment) Jul 30, 2024
@DaveSkender DaveSkender changed the title test: Performance tuning (stream hubs, increment experiment) test: Performance tuning (stream + incr experiments) Jul 30, 2024
@DaveSkender
Copy link
Owner Author

DaveSkender commented Jul 31, 2024

  • Check if Reusable can be contravariant to TReusable, or other in/out type keywords
    • apply to AlligatorHub and other HL2 scenarios to avoid excess casting overhead
  • Check if more interfaces can be used for input parameters, instead of concrete types, if performant
  • add notnull constraint to ISeries and remove incremental types null reference checks, if possible (may not work), seek other similar fixes

Signed-off-by: Dave Skender <[email protected]>
@DaveSkender
Copy link
Owner Author

  • test for CMO isUp works as expected when there’s no price change

@DaveSkender
Copy link
Owner Author

DaveSkender commented Oct 10, 2024

Minor improvements to QuoteHub and RenkoHub

Method Mean Error StdDev
AdlHub 34.411 μs 21.475 μs 1.1771 μs
AtrHub 41.800 μs 4.962 μs 0.2720 μs
AtrStopHub 77.144 μs 33.461 μs 1.8341 μs
AlligatorHub 48.238 μs 3.007 μs 0.1648 μs
EmaHub 28.427 μs 8.953 μs 0.4907 μs
QuoteHub 8.338 μs 1.511 μs 0.0828 μs
QuotePartHub 27.229 μs 11.569 μs 0.6341 μs
RenkoHub 40.373 μs 8.937 μs 0.4899 μs
SmaHub 36.289 μs 25.591 μs 1.4027 μs
TrHub 32.927 μs 7.490 μs 0.4106 μs

@DaveSkender
Copy link
Owner Author

Method Mean Error StdDev
AdlHub 34.356 us 4.0523 us 0.2221 us
AtrHub 42.367 us 11.7349 us 0.6432 us
AtrStopHub 70.069 us 1.8487 us 0.1013 us
AlligatorHub 47.881 us 5.5744 us 0.3056 us
EmaHub 26.778 us 2.4779 us 0.1358 us
EmaHub2 26.453 us 3.7542 us 0.2058 us
QuoteHub 8.293 us 2.0734 us 0.1137 us
QuotePartHub 27.764 us 4.2852 us 0.2349 us
RenkoHub 39.993 us 0.8697 us 0.0477 us
SmaHub 37.197 us 6.0623 us 0.3323 us
TrHub 33.422 us 10.2533 us 0.5620 us

@DaveSkender DaveSkender marked this pull request as ready for review October 27, 2024 21:56
@DaveSkender DaveSkender merged commit 45ce24f into v3-increments Oct 27, 2024
8 of 9 checks passed
@DaveSkender DaveSkender deleted the perf-tuning branch October 27, 2024 22:04
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

handle out-of-sequence late-arrival quotes
1 participant