Skip to content

fix: memory leaks in CacheExtension.render_id_to_cache_key and context_processors_data WeakKeyDictionary - #1613

Merged
EmilStenstrom merged 7 commits into
django-components:masterfrom
oliverhaas:fix/cache-render-id-memory-leak
Apr 25, 2026
Merged

EmilStenstrom merged 7 commits into
django-components:masterfrom
oliverhaas:fix/cache-render-id-memory-leak

Conversation

@oliverhaas

Copy link
Copy Markdown
Contributor

See accidentally messed up previous PR #1606 and issue #1607.

Entries were never removed. Two leak paths:
- on_component_rendered read the key but never popped it.
- on_component_input stored the key before checking the cache, so on
  cache hits the entry leaked because on_component_rendered never runs.
Cache context processor data on the request object itself instead of
a module-level WeakKeyDictionary, so the cache is automatically
cleaned up when the request is garbage collected.
@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [51b51a8] After [9a8e1f8] Ratio Benchmark (Parameter)
66.8±1ms 66.8±0.2ms 1 Components vs Django.timeraw_render_lg_first('django')
241±3ms 242±4ms 1 Components vs Django.timeraw_render_lg_first('django-components')

@EmilStenstrom

Copy link
Copy Markdown
Collaborator

@JuroOravec Mind having a look?

@github-actions

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [5a1cb92] After [c768fe5] Ratio Benchmark (Parameter)
70.7±1ms 72.1±0.9ms 1.02 Components vs Django.timeraw_render_lg_first('django')
251±4ms 255±4ms 1.02 Components vs Django.timeraw_render_lg_first('django-components')

@github-actions

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [069997c] After [2859bfd] Ratio Benchmark (Parameter)
68.5±1ms 68.4±1ms 1 Components vs Django.timeraw_render_lg_first('django')
243±2ms 243±3ms 1 Components vs Django.timeraw_render_lg_first('django-components')

@github-actions

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [f26b66b] After [24fbd04] Ratio Benchmark (Parameter)
69.6±1ms 69.7±1ms 1 Components vs Django.timeraw_render_lg_first('django')
245±2ms 251±4ms 1.02 Components vs Django.timeraw_render_lg_first('django-components')

@github-actions

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [22f1f2f] After [b9c2468] Ratio Benchmark (Parameter)
68.4±0.3ms 68.2±0.6ms 1 Components vs Django.timeraw_render_lg_first('django')
244±3ms 244±4ms 1 Components vs Django.timeraw_render_lg_first('django-components')

@github-actions

Copy link
Copy Markdown
Contributor

Performance Benchmark Results

Comparing PR changes against master branch:

Benchmarks that have stayed the same:

Change Before [22f1f2f] After [6ac579b] Ratio Benchmark (Parameter)
61.2±0.7ms 61.6±1ms 1.01 Components vs Django.timeraw_render_lg_first('django')
221±2ms 221±3ms 1 Components vs Django.timeraw_render_lg_first('django-components')

@EmilStenstrom
EmilStenstrom merged commit 28930c2 into django-components:master Apr 25, 2026
15 checks passed
@oliverhaas
oliverhaas deleted the fix/cache-render-id-memory-leak branch April 26, 2026 04:51
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

Successfully merging this pull request may close these issues.

2 participants