Flatten grid structure endpoint memory consumption#61273
Merged
kaxil merged 2 commits intoapache:mainfrom Feb 1, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes memory consumption in the grid structure endpoint by implementing streaming and immediate garbage collection of serialized DAG (serdag) objects. Instead of loading all serdags into memory before processing, the endpoint now processes them in batches of 5 and expunges them from the SQLAlchemy session after use.
Changes:
- Added streaming query execution using
yield_per(5)to process serdags in batches - Implemented immediate expunging of serdag objects after processing to enable garbage collection
- Refactored merging logic to process and merge DAGs incrementally instead of collecting all in memory first
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jedcunningham
commented
Jan 31, 2026
dheerajturaga
approved these changes
Jan 31, 2026
Member
dheerajturaga
left a comment
There was a problem hiding this comment.
Awesome! very large serdags with many versions is a common occurrence in our use case. Any and all optimizations are welcome in this space 😄
kaxil
approved these changes
Feb 1, 2026
eladkal
approved these changes
Feb 1, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
17ca80a to
c10b7f9
Compare
Member
|
#protm - Small but impactful change |
shashbha14
pushed a commit
to shashbha14/airflow
that referenced
this pull request
Feb 2, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
jason810496
pushed a commit
to abhijeets25012-tech/airflow
that referenced
this pull request
Feb 3, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
vatsrahul1001
pushed a commit
that referenced
this pull request
Feb 3, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
vatsrahul1001
added a commit
that referenced
this pull request
Feb 3, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly. (cherry picked from commit 40f6ec1)
vatsrahul1001
added a commit
that referenced
this pull request
Feb 3, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly. (cherry picked from commit 40f6ec1)
jhgoebbert
pushed a commit
to jhgoebbert/airflow_Owen-CH-Leung
that referenced
this pull request
Feb 8, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
Ratasa143
pushed a commit
to Ratasa143/airflow
that referenced
this pull request
Feb 15, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
choo121600
pushed a commit
to choo121600/airflow
that referenced
this pull request
Feb 22, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
Subham-KRLX
pushed a commit
to Subham-KRLX/airflow
that referenced
this pull request
Mar 4, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
vatsrahul1001
added a commit
that referenced
this pull request
Mar 4, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly. (cherry picked from commit 40f6ec1)
Ankurdeewan
pushed a commit
to Ankurdeewan/airflow
that referenced
this pull request
Mar 15, 2026
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together. Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The grid structure endpoint was loading all serdags for the shown dagruns into memory at once, before merging them together.
Now, we load 5 at a time and also expunge so they can be gc'd more quickly.
For normal simple dags this makes nearly no difference:
Before:
Average: 0.0163 secs
Requests/sec: 184.5453
95%% in 0.0225 secs
After:
Average: 0.0177 secs
Requests/sec: 169.2285
95%% in 0.0214 secs
But for "edge case" dags - those with many serdag versions shown on a single grid, and large serdag versions, it makes a significant difference and can be the difference between an healthy api server and one that OOMs.
Before:

Average: 12.5568 secs
Requests/sec: 0.0796
90%% in 12.9824 secs
After:

Average: 12.2856 secs
Requests/sec: 0.0814
90%% in 12.4549 secs
(This profiling was done with an intentionally bad dag to really highlight the difference)
Was generative AI tooling used to co-author this PR?
Generated-by: Cursor (Claude 4.5 Opus)
Generated-by: Gemini CLI (Gemini 3 Pro)