Open trajan0x opened 1 month ago
To speed up GetCommittableBalance
, follow these steps:
status
column in request_for_quotes
table is indexed.CREATE INDEX idx_status ON request_for_quotes(status);
Refactor GetCommittableBalances
: Cache the results of GetCommittableBalances
to avoid redundant database calls.
Update HasSufficientGas
: Refactor HasSufficientGas
to use the cached results.
Refactor Forward Functions: Update forward-Seen
, forward-CommittedPending
, and forward-CommittedConfirmed
to use the cached results.
Files to Update:
/services/rfq/handlers.go
: Modify GetCommittableBalances
function./services/rfq/gas.go
: Modify HasSufficientGas
function./services/rfq/forward.go
: Modify forward-Seen
, forward-CommittedPending
, and forward-CommittedConfirmed
functions.Example Code:
// Cache structure
var committableBalanceCache map[string]Balance
// GetCommittableBalances with caching
func GetCommittableBalances() Balance {
if balance, found := committableBalanceCache["key"]; found {
return balance
}
// Original SQL query
balance := queryDatabase()
committableBalanceCache["key"] = balance
return balance
}
// HasSufficientGas using cached balance
func HasSufficientGas() bool {
balance := GetCommittableBalances()
// Logic to check gas
}
This approach reduces redundant database calls and improves performance.
/services/rfq/relayer/inventory/manager.go /docs/bridge/docs/rfq/API/upsert-quote.api.mdx /agents/contracts/test/attestationharness/generate.go /services/rfq/relayer/service/handlers.go /packages/solidity-devops/src/SynapseScript06.sol /agents/contracts/test/snapshotharness/generate.go /services/rfq/relayer/quoter/quoter.go /services/rfq/README.md /agents/testutil/agentstestcontract/agentstestcontract.contractinfo.json /services/rfq /contrib/opbot/botmd/commands.go /services/rfq/api/docs/swagger.yaml /packages/solidity-devops/src/SynapseScript.sol /agents/contracts/summit/generate.go /packages/sdk-router/src/sdk.test.ts /packages/contracts-rfq/deployments/op_sepolia /agents/contracts/test/summitharness/summitharness.metadata.go /agents/contracts/test/summitharness/doc.go /agents/contracts/test/gasdata/generate.go /contrib/screener-api/docs/swagger.json /ethergo/submitter/README.md /services/rfq/contracts/fastbridge/fastbridge.metadata.go /agents/contracts/test/summitharness /services/omnirpc/proxy/response_test.go /docs/bridge/docs/rfq/API/upsert-quotes.api.mdx
As I was going through a trace to look for speedup opps I've realized 90% of our latency exists in a single sql query:
SELECT * FROM
request_for_quotesWHERE status IN (5,6,7)
This query is called in GetCommittableBalances which is called in
HasSufficientGas
which in turn is called twice sequentially (#2960).Amazingly, it's then called a third time in
forward-Seen
:Moving on to forward-ComimttedPending we call it 2x more sequentially
Then again in 2x more in forward-CommittedConfirmed: