[8] graph/db: use batch loading for various graph SQL methods#10129
[8] graph/db: use batch loading for various graph SQL methods#10129ellemouton merged 9 commits intolightningnetwork:masterfrom
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @ellemouton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request focuses on optimizing the native SQL graph store by implementing batch loading for several critical graph database operations. The primary goal is to reduce the number of individual database queries, thereby significantly improving the performance of methods responsible for fetching, deleting, and pruning channel and node information within the graph.
Highlights
- Performance Improvement: This pull request significantly improves the performance of several graph SQL methods by introducing batch loading. For example, benchmarks show
ChanUpdatesInHorizonperformance improving by 89.11% for native SQLite and 98.65% for native PostgreSQL. - Batch Loading Implementation: Introduced generic batch loading functions (
batchBuildChannelEdges,batchBuildChannelInfo) to efficiently retrieve channel, policy, and node data from the SQL database. These functions minimize individual database queries by fetching related data in bulk. - Refactored Graph Store Methods: The following
SQLStoremethods have been refactored to leverage the new batch loading capabilities:ChanUpdatesInHorizon,DeleteChannelEdges,PruneGraph,DisconnectBlockAtHeight, andFetchChanInfos. This replaces previous individual data fetching loops with more optimized batch operations. - New Interfaces for Genericity: Two new interfaces,
ChannelAndNodesandChannelAndNodeIDs, have been introduced insqldb/sqlc/db_custom.go. These interfaces provide a common contract for differentsqlcgenerated row types, enabling the new batch loading functions to operate generically across various query results.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces batch loading for several graph SQL methods, improving performance. The changes include modifications to benchmark tests, KV store, SQL migration, and SQL store files. The code adheres to the style guide, but some line lengths exceed 80 characters and could be wrapped for better readability. Additionally, some comments could be improved for clarity.
guggero
left a comment
There was a problem hiding this comment.
-98.65%, that's some epic gainz!!!
Great stuff, LGTM 🎉
Let the helper method only take the params it needs so that we dont need to construct an entire models.ChannelEdgeInfo object to pass to it. This will be useful later on.
Since the type returned from the DB is not a pointer. This will be useful later on.
The following performance gains were measured using the new benchmark test. ``` name old time/op new time/op delta ChanUpdatesInHorizon-native-sqlite-10 18.5s ± 3% 2.0s ± 5% -89.11% (p=0.000 n=9+9) ChanUpdatesInHorizon-native-postgres-10 59.0s ± 3% 0.8s ±10% -98.65% (p=0.000 n=10+9) ```
Depends on #10127
Part of #9795
This PR continues with performance improvements for the native SQL graph store. This is done for methods:
Example performance improvement of ChanUpdatesInHorizon:
The new benchmark test is used to measure the performance improvement of the ChanUpdatesInHorizon call: