-
Notifications
You must be signed in to change notification settings - Fork 820
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
orderbook: Refactor package structure for simplicity and efficiency #1465
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1465 +/- ##
==========================================
+ Coverage 36.00% 37.77% +1.76%
==========================================
Files 412 409 -3
Lines 177779 147712 -30067
==========================================
- Hits 64017 55794 -8223
+ Misses 105902 84052 -21850
- Partials 7860 7866 +6
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the simplification, even though many functions appear to remain very similar 🎉
I'll definitely be doing more rounds of testing for this important code. I've mostly just questioned benchmarking for now :D
exchanges/orderbook/Tranches.go
Outdated
@@ -0,0 +1,669 @@ | |||
package orderbook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please Make This A Lower Case File, Thanks! Unless There is A New Thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After making the master
branch benchmarks equivalent to your updates, the main downside I'm seeing is sorting performance, which isn't used very much thankfully.
Overall, I find the simplification of manipulating a slice over having a linked list to be an improvement, even if some of the benchmarks for me aren't drastic. I have found no problems with orderbook checksum calculation or anything during testing.
benchmark | master time | this branch time | master bytes | this branch bytes | master allocs | this branch allocs |
---|---|---|---|---|---|---|
BenchmarkUpdateByID-10 | 18.34 ns/op | 18.92 ns/op | 0 B/op | 0 B/op | 0 allocs/op | 0 allocs/op |
BenchmarkLoad-10 | 72.87 ns/op | 23.01 ns/op | 0 B/op | 0 B/op | 0 allocs/op | 0 allocs/op |
BenchmarkUpdateInsertByPrice_Amend-10 | 37.13 ns/op | 5.698 ns/op | 0 B/op | 0 B/op | 0 allocs/op | 0 allocs/op |
BenchmarkUpdateInsertByPrice_Insert_Delete-10 | 58.17 ns/op | 53.03 ns/op | 0 B/op | 0 B/op | 0 allocs/op | 0 allocs/op |
BenchmarkRetrieve-10 | 111.2 ns/op | 106.3 ns/op | 480 B/op | 480 B/op | 1 allocs/op | 1 allocs/op |
BenchmarkUpdateInsertByID_bids-10 | 49.06 ns/op | 51.26 ns/op | 0 B/op | 0 B/op | 0 allocs/op | 0 allocs/op |
BenchmarkDeleteByID-10 | 207.6 ns/op | 151.2 ns/op | 0 B/op | 480 B/op | 0 allocs/op | 1 allocs/op |
BenchmarkUpdateInsertByID_asks-10 | 38.11 ns/op | 38.66 ns/op | 0 B/op | 0 B/op | 0 allocs/op | 0 allocs/op |
BenchmarkReverse-10 | 2845 ns/op | 2826 ns/op | 0 B/op | 0 B/op | 0 allocs/op | 0 allocs/op |
BenchmarkSortAsksDecending-10 | 4081 ns/op | 4269 ns/op | 24 B/op | 152 B/op | 1 allocs/op | 3 allocs/op |
BenchmarkSortBidsAscending-10 | 4707 ns/op | 4181 ns/op | 41 B/op | 152 B/op | 2 allocs/op | 3 allocs/op |
BenchmarkSortAsksStandard-10 | 68287 ns/op | 95506 ns/op | 39 B/op | 172 B/op | 1 allocs/op | 3 allocs/op |
BenchmarkSortBidsStandard-10 | 86231 ns/op | 94179 ns/op | 58 B/op | 172 B/op | 2 allocs/op | 3 allocs/op |
BenchmarkSortAsksAscending-10 | 4137 ns/op | 4302 ns/op | 24 B/op | 152 B/op | 1 allocs/op | 3 allocs/op |
BenchmarkSortBidsDescending-10 | 4710 ns/op | 4237 ns/op | 41 B/op | 152 B/op | 2 allocs/op | 3 allocs/op |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK! Thanks Shazbert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK, running OKX/Kraken and Bitfinex websocket stream, no checksum issues. Tests happy. Benchmarks for sec/op of old vs new on my system at the cost of slightly more allocs. Nice stuff!
goos: windows
goarch: amd64
pkg: github.com/thrasher-corp/gocryptotrader/exchanges/orderbook
cpu: AMD Ryzen Threadripper 3970X 32-Core Processor
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
Load-64 62.00n ± 0% 16.23n ± 1% -73.81% (p=0.000 n=10)
Reverse-64 2.945µ ± 2% 2.960µ ± 2% ~ (p=1.000 n=10)
SortAsksAscending-64 21.724µ ± 4% 3.792µ ± 1% -82.55% (p=0.000 n=10)
SortAsksDecending-64 21.655µ ± 19% 3.770µ ± 1% -82.59% (p=0.000 n=10)
SortAsksStandard-64 117.8µ ± 2% 110.2µ ± 1% -6.47% (p=0.000 n=10)
SortBidsAscending-64 23.376µ ± 10% 3.789µ ± 1% -83.79% (p=0.000 n=10)
SortBidsDescending-64 23.498µ ± 4% 3.765µ ± 0% -83.98% (p=0.000 n=10)
SortBidsStandard-64 132.5µ ± 1% 107.6µ ± 1% -18.82% (p=0.000 n=10)
UpdateByID-64 30.54n ± 0% 24.00n ± 1% -21.44% (p=0.000 n=10)
UpdateInsertByPrice_Amend-64 10.065n ± 1% 6.857n ± 1% -31.87% (p=0.000 n=10)
UpdateInsertByPrice_Insert_Delete-64 30.32n ± 3% 46.98n ± 1% +54.96% (p=0.000 n=10)
geomean 2.232µ 990.2n -55.64%
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
Load-64 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
Reverse-64 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
SortAsksAscending-64 2.000 ± 0% 3.000 ± 0% +50.00% (p=0.000 n=10)
SortAsksDecending-64 2.000 ± 0% 3.000 ± 0% +50.00% (p=0.000 n=10)
SortAsksStandard-64 2.000 ± 0% 3.000 ± 0% +50.00% (p=0.000 n=10)
SortBidsAscending-64 3.000 ± 0% 3.000 ± 0% ~ (p=1.000 n=10) ¹
SortBidsDescending-64 3.000 ± 0% 3.000 ± 0% ~ (p=1.000 n=10) ¹
SortBidsStandard-64 3.000 ± 0% 3.000 ± 0% ~ (p=1.000 n=10) ¹
UpdateByID-64 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
UpdateInsertByPrice_Amend-64 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
UpdateInsertByPrice_Insert_Delete-64 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
geomean ² +11.69% ²
PR Description
Update orderbook package. This is an initial update before I implement options books complimentary to #1082.
Initial benchmarks on my machine suggest a slight performance boost (when deleting it has performance hit 😭, but everything else is pretty schnappy) resulting from the changes introduced in this pull request.
Type of change
Please delete options that are not relevant and add an
x
in[]
as item is complete.How has this been tested
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and
also consider improving test coverage whilst working on a certain feature or package.
Checklist