Mastery Series
Welcome back for another instalment of the SubQuery Mastery Series, where we help you master the SubQuery Network and ensure your data needs are satisfied! In this article, we’ll focus on optimising your indexer's performance so you can achieve the highest level of SubQuery’s indexing performance that we’ve worked hard to reach.
Performance is a crucial factor in quickly accessing the on-chain data you need, both in terms of initial indexing sync times, as well as indexer latency from when events are finalised on chain. So, how can you optimise your SubQuery project to speed it up? Fortunately, there are several things you can do to improve indexing and query speed.
Read on for our hottest tips covering the most common issues, reviewing your indexer’s overall architecture and other advice.
Avoid Using Block Handlers Where Possible
blockHandlers can slow down your project as they are executed on every block. Use them only when absolutely necessary, and consider adjusting the project architecture to reduce reliance on them.
Always Use a Dictionary
Use Filter Conditions in Mapping Handlers
Set Start Block in Project Manifest
Leverage Node Worker Threads
When your project involves indexing a large volume of data (blocks, transactions, and more specific data) it’s wise to consider splitting it into separate SubQuery indexing projects, each responsible for different data sources. This approach mirrors the architectural decision between using microservices or sticking with a monolithic design in software development.
Why should you consider this separation? For one, indexing all blocks can be a time-consuming process that slows your project down significantly. If you later need to make changes—such as adjusting filters or altering the shape of your entities—you might have to clear your entire database and reindex the project from scratch. In large projects, this reindexing can take a lot of time and resources.
A practical example of this strategy is to create a larger project that indexes everything for internal analysis of your contracts, alongside a smaller, optimised project specifically designed for your dApp. The larger, all-encompassing project might remain static and only require initial indexing, avoiding the costly process of reindexing. Meanwhile, the smaller, optimised project can evolve alongside your dApp, and when changes are needed, reindexing will be much quicker and more manageable.
This separation offers a smoother development experience and a more efficient workflow. By isolating tasks, you can iterate faster on the parts that matter most to your users, without being bogged down by the slower indexing of everything else. It’s an approach that balances performance, flexibility, and scalability—one that can set your project up for long-term success.
When building data-intensive projects, particularly historical ones, optimising indexing performance is key to maintaining speed and efficiency. Here are some crucial tips to help you enhance the performance of your indexing processes:
Add Indexes to Boost Query Performance
Leverage Parallel and Batch Processing
Minimise External API Calls
Enable Reverse Lookups
Simplify Your Schema Design
Handle BigInts with Care
When working with GraphQL, optimising query performance is essential to maintaining fast and efficient data retrieval. Here are some best practices that can help you get the most out of your queries:
Use Cursor-Based Pagination for Better Efficiency
Query Only the Fields You Need
Avoid Querying totalCount Without Conditions for Large Data Tables
Restrict Query Complexity for Greater Control
By following these tips, you'll ensure faster, more efficient queries, leading to better performance across your entire project. Small adjustments can make a big difference when scaling your dApp or handling larger datasets!
More information is focused on the DevOps and configuration of running high-performance SubQuery projects here.
By following the strategies outlined in this article—whether it's leveraging parallel processing, reducing unnecessary API calls, or designing an efficient schema—you can unlock significant improvements in speed and efficiency. The key takeaway is to be mindful of how data is handled at every stage, from indexing to querying, allowing your project to grow without being weighed down by performance bottlenecks. With these tips in hand, you'll be well on your way to running a high-performance SubQuery project that meets your data needs, now and in the future.
SubQuery Network is innovating web3 infrastructure with tools that empower builders to decentralise the future. Our fast, flexible, and open data indexer supercharges dApps on over 200 networks, enabling a user-focused web3 world. Soon, our Data Node will provide breakthroughs in the RPC industry, and deliver decentralisation without compromise. We pioneer the web3 revolution for visionaries and forward-thinkers. We’re not just a company — we’re a movement driving an inclusive and decentralised web3 era. Let’s shape the future of web3, together.
Linktree | Website | Discord | Telegram | Twitter | Blog | Medium | LinkedIn | YouTube