Skip to content

Remove unnecessary buffer allocation/copy in FprimeRouter for file and unknown packets#30

Open
devin-ai-integration[bot] wants to merge 7 commits intodevelfrom
devin/1775773184-fprime-router-no-copy
Open

Remove unnecessary buffer allocation/copy in FprimeRouter for file and unknown packets#30
devin-ai-integration[bot] wants to merge 7 commits intodevelfrom
devin/1775773184-fprime-router-no-copy

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot commented Apr 9, 2026

Related Issue(s) N/A
Has Unit Tests (y/n) y (updated)
Documentation Included (y/n) y (SDD updated)
Generative AI was used in this contribution (y/n) y

Change Description

Svc::FprimeRouter previously allocated a new buffer and copied incoming data for both file and unknown packet types before forwarding. This was done so the original buffer could be immediately returned to the deframer via dataReturnOut.

This PR removes that allocation/copy. Instead, the original buffer is passed directly to the receiver on fileOut / unknownDataOut. The buffer is not returned to the deframer until it comes back on fileBufferReturnIn, at which point dataReturnOut is invoked with an empty ComCfg::FrameContext.

Specifically:

  • dataIn_handler: Each switch case now explicitly handles its own buffer return. The command case returns the buffer immediately after dispatching. The file and unknown cases pass the buffer through to the receiver when the port is connected (deferring return to fileBufferReturnIn), or return it immediately when the port is unconnected.
  • fileBufferReturnIn_handler: Now calls dataReturnOut_out with an empty context instead of bufferDeallocate_out.
  • FPP model: Removed bufferAllocate, bufferDeallocate output ports, AllocationReason enum, and AllocationError event.
  • Subtopologies: Removed dangling fprimeRouter.bufferAllocate and fprimeRouter.bufferDeallocate connections from both ComFprime.fpp and ComCcsds.fpp.
  • Unit tests: Removed testAllocationFailureFile and testAllocationFailureUnknown. Updated remaining tests to reflect that dataReturnOut is no longer invoked during file/unknown routing, and that testBufferReturn now asserts dataReturnOut instead of bufferDeallocate.
  • SDD: Updated memory management description and requirements table.

Rationale

The buffer copy was unnecessary — the router can simply pass the buffer through and defer returning it to the deframer. This simplifies the component, removes the dependency on a buffer allocator, and eliminates a potential allocation failure path.

Testing/Review Recommendations

Key areas for review:

  1. Buffer ownership semantics change (breaking): Downstream components receiving buffers on fileOut or unknownDataOut must return them via fileBufferReturnIn or the buffers will never be returned to the deframer. Verify that FileUplink and any custom routers already follow this contract.
  2. Empty context on return: fileBufferReturnIn_handler constructs a default ComCfg::FrameContext — the original context from dataIn is discarded. Confirm no downstream consumer of dataReturnOut relies on context data.
  3. Removed FPP ports/events (breaking): Any topology connecting bufferAllocate or bufferDeallocate on this component, or referencing AllocationError, will need updating. The two in-tree subtopologies (ComFprime, ComCcsds) have been updated in this PR — check for any out-of-tree references.

Unit tests were updated and pass locally (6/6).

Human Review Checklist

  • Confirm FileUplink returns buffers via fileBufferReturnIn (not some other path)
  • Confirm no out-of-tree topologies reference the removed bufferAllocate/bufferDeallocate ports
  • Confirm nothing downstream of dataReturnOut depends on a populated FrameContext

Future Work

  • Consider renaming fileBufferReturnIn to something more generic (e.g. bufferReturnIn) since it now serves as the return path for both file and unknown buffers.

AI Usage (see policy)

Generative AI (Devin / Claude) was used for code generation, test updates, and documentation updates under human direction.

Link to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/bfc230d4f2ed448f8b88cbb457ca1456


Open with Devin

…d unknown packets

Instead of allocating a new buffer and copying data for file and unknown
packet types, pass the original buffer directly to the receiver. The
buffer is not returned to the deframer via dataReturnOut until it comes
back on fileBufferReturnIn, at which point an empty context is
constructed for the return.

This eliminates the need for bufferAllocate and bufferDeallocate ports,
as well as the AllocationReason enum and AllocationError event.

Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
@devin-ai-integration
Copy link
Copy Markdown
Author

Original prompt from michael.d.starch

In F Prime, we have Svc/FprimeRouter. Currently, it performs an allocation and copies the buffer for (unknown, file) buffers. However, this copy is not necessary. Instead it could just pass the buffer out, and not return it until it gets a return. Please make this change for me. Make sure to update the UTs.

You'll find that the context object is effectively discarded. For now, construct an empty context for the return. Thanks!

@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration bot and others added 6 commits April 9, 2026 22:29
…pologies

Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…urn contract, document context discard

Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
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