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

Speed up GetCommittableBalance #2962

Open
trajan0x opened this issue Jul 30, 2024 · 1 comment
Open

Speed up GetCommittableBalance #2962

trajan0x opened this issue Jul 30, 2024 · 1 comment

Comments

@trajan0x
Copy link
Contributor

image

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_quotes WHERE 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:

image

Moving on to forward-ComimttedPending we call it 2x more sequentially

image

Then again in 2x more in forward-CommittedConfirmed:

image
Copy link

greptile-apps bot commented Jul 30, 2024

To speed up GetCommittableBalance, follow these steps:

  1. Optimize SQL Query: Modify the SQL query to use indexes. Ensure status column in request_for_quotes table is indexed.
CREATE INDEX idx_status ON request_for_quotes(status);
  1. Refactor GetCommittableBalances: Cache the results of GetCommittableBalances to avoid redundant database calls.

  2. Update HasSufficientGas: Refactor HasSufficientGas to use the cached results.

  3. 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.

References

/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

About Greptile

This response provides a starting point for your research, not a precise solution.

Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

Ask Greptile · Edit Issue Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant