Skip to content

feat: add getMemoryStats endpoint to registry#486

Open
rvanasa wants to merge 9 commits intomainfrom
registry-memory-stats
Open

feat: add getMemoryStats endpoint to registry#486
rvanasa wants to merge 9 commits intomainfrom
registry-memory-stats

Conversation

@rvanasa
Copy link
Copy Markdown
Collaborator

@rvanasa rvanasa commented Apr 10, 2026

This PR adds an admin-only query endpoint that reports entry counts and Candid-serialized byte counts for analyzing what data structures account for the most storage overhead in the registry canister.

getMemoryStats is a query method gated behind Utils.isAdmin(caller). It returns:

  • Runtime metrics: rts_heap_size and rts_memory_size from mo:prim
  • Per-structure stats: { count : Nat; bytes : Nat } for all data structures across the main actor, DownloadLog, StorageManager, and Users

@rvanasa rvanasa requested a review from Copilot April 10, 2026 16:13
@rvanasa rvanasa marked this pull request as ready for review April 10, 2026 16:14
@rvanasa rvanasa requested a review from a team as a code owner April 10, 2026 16:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an admin-only getMemoryStats query endpoint to the registry canister to report runtime RTS memory metrics and per-data-structure {count, bytes} estimates (via Candid serialization sizing) for storage overhead analysis.

Changes:

  • Extended the public Candid interface with StructureStats, MemoryStats, and getMemoryStats.
  • Implemented getMemoryStats in the main canister, including RTS heap/memory metrics and per-structure aggregation.
  • Added internal getMemoryStats helpers to DownloadLog, StorageManager, and Users to report their respective structure stats.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
cli/declarations/main/main.did Adds StructureStats/MemoryStats types and the getMemoryStats service method.
backend/main/main-canister.mo Implements the admin-only query and aggregates stats across in-canister structures and submodules.
backend/main/DownloadLog.mo Adds stats computation for download maps, snapshot buffers, and temp records.
backend/storage/storage-manager.mo Adds stats computation for storage maps.
backend/main/Users.mo Adds stats computation for the users map.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

rvanasa added 3 commits April 10, 2026 13:13
- Change getMemoryStats from query to update to avoid hitting query
  instruction limits when serializing all entries via to_candid
- Bump API_VERSION to 1.4 in backend and CLI (paired change)
- Update cli/declarations/main/main.did.js and main.did.d.ts with
  StructureStats and MemoryStats types, and getMemoryStats method
- Add unit tests for getMemoryStats in test/users.test.mo and
  test/download-log.test.mo

Made-with: Cursor
Replace full-iteration to_candid calls with a systematic sample of up
to 10,000 entries per data structure. The sampled byte total is
extrapolated linearly (sampleBytes * total / sampled), so the result
remains a useful approximation while keeping allocations bounded
regardless of registry size.

Made-with: Cursor
Sampling keeps to_candid calls bounded to ~10,000 per structure, so
query instruction limits are no longer a concern.

Made-with: Cursor
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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