-
Notifications
You must be signed in to change notification settings - Fork 14
Reduce UI lag: gate redundant Monero callbacks #102
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,9 @@ const SAVE_DATASTORE_MILLISECONDS = 10000 | |
|
|
||
| const PRIMARY_CURRENCY_TOKEN_ID = null | ||
|
|
||
| // Global throttle: max 1 onAddressesChecked per 500ms; ratio=1 always passes. | ||
| let lastSyncEmitTime = 0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: Recommendation: Move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Global throttle variable shared across all engine instancesMedium Severity
Additional Locations (1) |
||
|
|
||
| export class MoneroEngine implements EdgeCurrencyEngine { | ||
| apiKey: string | ||
| walletInfo: SafeWalletInfo | ||
|
|
@@ -169,6 +172,9 @@ export class MoneroEngine implements EdgeCurrencyEngine { | |
| return | ||
| } | ||
| if (numTx !== totalTxs) { | ||
| const now = Date.now() | ||
| if (now - lastSyncEmitTime < 500) return | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning: The 500ms throttle interval is a magic number. It's not discoverable at the top of the file alongside the other interval constants ( Recommendation: Extract to a named constant: |
||
| lastSyncEmitTime = now | ||
|
Comment on lines
174
to
+177
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning: The throttle drops progress callbacks entirely with no trailing-edge emit. The UI may jump from e.g. 30% directly to 100% if the last sub-100% update is suppressed. For wallets with many transactions where progress updates happen rapidly, intermediate progress values are silently discarded. Recommendation: Consider a trailing-edge throttle (schedule a deferred emit when one is suppressed) so the most recent progress value is always delivered before the final 100% callback. |
||
| const progress = numTx / totalTxs | ||
| this.edgeTxLibCallbacks.onAddressesChecked(progress) | ||
| } else { | ||
|
|
@@ -304,8 +310,10 @@ export class MoneroEngine implements EdgeCurrencyEngine { | |
| } | ||
|
|
||
| this.saveTransactionState(PRIMARY_CURRENCY_TOKEN_ID, edgeTransaction) | ||
| this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray) | ||
| this.transactionEventArray = [] | ||
| if (this.transactionEventArray.length > 0) { | ||
| this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray) | ||
| this.transactionEventArray = [] | ||
| } | ||
|
Comment on lines
312
to
+316
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning: Recommendation: Consider moving the |
||
|
|
||
| return blockHeight | ||
| } | ||
|
|
@@ -343,11 +351,13 @@ export class MoneroEngine implements EdgeCurrencyEngine { | |
| } | ||
|
|
||
| this.updateOnAddressesChecked(transactions.length, transactions.length) | ||
| // Update the seenTxCheckpoint state: | ||
| this.seenTxCheckpoint = seenTxCheckpoint | ||
| this.edgeTxLibCallbacks.onSeenTxCheckpoint( | ||
| wasSeenTxCheckpoint(this.seenTxCheckpoint) | ||
| ) | ||
| // Only update the seenTxCheckpoint if it actually advanced: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The comment says 'if it actually advanced' but the comparison checks for any change ( Recommendation: Change to: |
||
| const newCheckpoint = wasSeenTxCheckpoint(seenTxCheckpoint) | ||
| const oldCheckpoint = wasSeenTxCheckpoint(this.seenTxCheckpoint) | ||
|
Comment on lines
+355
to
+356
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The checkpoint comparison serializes both values via Recommendation: Compare |
||
| if (newCheckpoint !== oldCheckpoint) { | ||
| this.seenTxCheckpoint = seenTxCheckpoint | ||
| this.edgeTxLibCallbacks.onSeenTxCheckpoint(newCheckpoint) | ||
| } | ||
| } catch (e) { | ||
| this.log.error('checkTransactionsInnerLoop', e) | ||
| } | ||
|
|
@@ -457,10 +467,8 @@ export class MoneroEngine implements EdgeCurrencyEngine { | |
| doInitialCallbacks(): void { | ||
| for (const tokenId of this.walletLocalData.enabledTokens) { | ||
| try { | ||
| this.edgeTxLibCallbacks.onTokenBalanceChanged( | ||
| tokenId, | ||
| this.walletLocalData.totalBalances.get(tokenId) ?? '0' | ||
| ) | ||
| const _bal = this.walletLocalData.totalBalances.get(tokenId) ?? '0' | ||
| this.edgeTxLibCallbacks.onTokenBalanceChanged(tokenId, _bal) | ||
|
Comment on lines
+470
to
+471
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The Recommendation: Rename to |
||
| } catch (e) { | ||
| this.log.error('Error for currencyCode', tokenId, e) | ||
| } | ||
|
|
||


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.
Suggestion: The comment 'ratio=1 always passes' uses jargon that doesn't map to the code's variable names (
numTx/totalTxs). It takes a moment to understand this means the final 100% callback bypasses the throttle.Recommendation: Reword to:
// Global throttle: max 1 onAddressesChecked call per 500ms for in-progress syncs. The final 100% callback is never throttled.