Skip to content

App session clean v1#916

Open
brendanobra wants to merge 41 commits intomainfrom
app-session-clean-v1
Open

App session clean v1#916
brendanobra wants to merge 41 commits intomainfrom
app-session-clean-v1

Conversation

@brendanobra
Copy link
Copy Markdown
Contributor

What

What does this PR add or remove?

Why

Why are these changes needed?

How

How do these changes achieve the goal?

Test

How has this been tested? How can a reviewer test it?

Checklist

  • I have self-reviewed this PR
  • I have added tests that prove the feature works or the fix is effective

Critical Memory Leak Fix:
- Fixed incomplete session cleanup in remove_session_from_events()
- Changed from removing only first EventListener to removing ALL listeners per session
- Used retain() instead of manual remove(index) for comprehensive cleanup
- Added test_remove_session_removes_all_listeners() to prevent regression

Memory leak was causing 1-4KB retention per session with multiple event listeners,
scaling linearly with Firebolt API usage. This was particularly problematic on
embedded aarch64 devices with constrained memory.

Struct Alignment Optimizations:
- Optimized CallContext field ordering to reduce padding (~8 bytes saved per instance)
- Eliminated SessionData wrapper in Session struct for better cache locality
- Reordered PendingSessionInfo fields to minimize internal padding
- Improved memory alignment for frequently allocated structures

Impact:
- Eliminates proportional memory growth with Firebolt API calls
- Reduces per-EventListener memory overhead by 8+ bytes
- Improves cache locality and reduces heap fragmentation
- Critical for embedded deployment on memory-constrained devices

All tests pass (27 session-related tests), no functional regressions.
Validated with clippy and comprehensive test suite.

# Memory allocator: jemalloc with aggressive settings for embedded platforms
tikv-jemallocator = { version = "0.6", features = ["unprefixed_malloc_on_supported_platforms", "background_threads"] }
tikv-jemalloc-ctl = "0.6"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jemalloc is better at dealing with fragementation, and sets us up for next steps. The gains (reductions, actually) are not that dramatic in this iteration, but it does actually decrease a little when references are dropped

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 6, 2025

Code Coverage

Package Line Rate Health
core.main.src.bootstrap.extn 0%
core.main.src.service.extn 24%
core.sdk.src.api 45%
core.main.src.broker.test 90%
core.main.src.bootstrap.manifest 0%
core.main.src.broker 73%
core.main.src.firebolt.handlers 11%
core.main.src.state 35%
core.main.src 0%
core.sdk.src.service.mock_app_gw.appgw 0%
core.sdk.src.api.firebolt 85%
device.thunder_ripple_sdk.src.bootstrap 0%
core.sdk.src.service.mock_app_gw 0%
device.thunder_ripple_sdk.src.events 4%
core.main.src.service.ripple_service 9%
core.sdk.src.api.manifest 74%
core.sdk.src.api.device 76%
core.main.src.bootstrap 0%
core.main.src.utils 30%
core.sdk.src.api.observability 57%
core.sdk.src.processor 6%
core.sdk.src.framework 64%
core.sdk.src.api.gateway 69%
core.sdk.src 78%
core.tdk.src.gateway 100%
core.tdk.src.utils 0%
device.thunder_ripple_sdk.src.client 61%
device.thunder_ripple_sdk.src 13%
core.sdk.src.manifest 0%
core.sdk.src.service 41%
core.main.src.broker.rules 78%
core.main.src.service.apps 25%
core.main.src.state.cap 42%
core.sdk.src.utils 63%
core.sdk.src.extn 76%
core.main.src.broker.thunder 37%
core.main.src.processor.storage 0%
core.sdk.src.api.distributor 29%
device.mock_device.src 55%
device.thunder_ripple_sdk.src.processors 19%
core.main.src.processor 0%
core.sdk.src.extn.ffi 0%
core.main.src.firebolt 22%
core.main.src.service 32%
core.sdk.src.extn.client 82%
device.thunder_ripple_sdk.src.processors.events 0%
Summary 50% (22653 / 45628)

Minimum allowed line rate is 48%

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.

1 participant