In the third Developer Highlights, we continue our talk with Ivan Herger (@ivan) and Sebastian Siemssen (@fubhy) from Enzyme Finance. If you haven’t seen the first part, I highly recommend checking it out.
In this part we take on our most requested topic for developer highlights - subgraph performance. Sebastian and Ivan have two years of experience making subgraphs for Enzyme Finance. Learn how they have optimized their subgraph to meet the scaling requirements of a truly ambitious DeFi subgraph. We also talk about Timeseries data tracking and AssemblyScript quirks.
- Performance Tips
- Timeseries Data Tracking
- AssemblyScript Quirks
Watch the full episode, or jump straight to each topic using the timestamps below the video.
00:00 Overview
Performance Tips - Manifest
02:25 Setting a startblock
03:44 Choosing what handlers to use
04:11 Avoiding contract calls
05:13 Contract calls are run at block number
08:12 Avoid block handlers
10:45 Filtering events in the manifest
12:46 Observing all ERC20 Transfer Events
Performance Tips - Mappings
14:36 Filtering events in the mappings
17:21 Avoiding redundancy with “internal” data
19:13 Saving entities without loading
20:08 Using helper Functions.
23:53 Save/Load calls are cached
Performance Tips - Schema
25:38 Reverse Lookups (derivedFrom)
27:33 Reverse Lookups example
28:32 Using the Schema to store state (counting+)
31:02 Subgraph design trick - Makeshift cron handler
Performance Tips - Querying
32:20 Include both lower and upper bounds
Timeseries data tracking
34:51 Using timewindows
37:19 Timewindows in the schema
40:29 Benefits of using timewindows
41:06 Using timewindows for tracking other states
43:18 Daily and hourly timewindows
44:22 Querying timeranges using time-travel queries
47:30 Loading the last record of the previous timewindow
AssemblyScript Quirks
50:42 Array utilities
52:54 Assemblyscript array bug
54:03 Scope not being inherited into closures
55:33 Other utilities
We encourage anyone to ask questions about these topics below.