fix(twap): fix infinite loop in orders hook #3348
Merged
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
While testing I noticed that my M2 Max processor sometimes freezes.
By stopping the main thread periodically I noticed that I almost always get into
CreatedInOrderBookOrdersUpdater
.After adding a
console.log
here I saw that it gets tons of recalculations forpartOrdersFromProd
.After some bisection on
useAsyncMemo
deps I got intouseSWRProdOrders
and here I found the cause of the problem.So, the main problem in the fact that we always return a new array and it makes
useAsyncMemo()
recalculate everything many times.tttt.mov
To Test
console.log
like:Before the fix I got tons of console logs. After only few