Skip to content

Conversation

saintentropy
Copy link
Contributor

@saintentropy saintentropy commented Jun 12, 2025

Purpose

Some targeted improvements for graph execution. Primarily for delivery in performance of graphs large data sets. In my test graph reduced average graph execution runtime ~ 15% and tessellation by ~5%

Includes algorithm enhancements:

  • DEP_Hander calls in AssociativeGraph.cs -> Remove use of linq in hot path
  • PopTo Calls in Executive.cs / RuntimeMemory.cs -> Combine symbol node lookup and update
  • Marshaling Calls in Heap.cs -> Streamline heap object allocation for creating of DSObjects when marshaling CLR types
  • Marshaling Calls in CLRObjectMarshaller.cs -> Optimize IsAssignableFromDictionary, etc

Includes allocation enhancements

  • ExecWithRISlowPath in Callsite.cs -> Use ReadOnlySpan where possible and initialize List sizes where possible

Includes these caching enhancements

  • PopTo Calls in Executive -> Cache last symbol lookup for repeated calls (say in replication loop). This cache stays within the lifetime of the executive (need to confirm this does not need to be reset)
  • Data / GetElements in MirrorData -> Cache and pre-assign Marshaller and Interpreter within MirroData constructor within GetElements() calls. Subsequent Data calls can directly use the assigned Marshaller. This is primarily useful in tessellation and previous bubble workflows.

Declarations

Check these if you believe they are true

  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB
  • This PR introduces new feature code involve network connecting and is tested with no-network mode.

Release Notes

(FILL ME IN) Brief description of the fix / enhancement. Use N/A to indicate that the changes in this pull request do not apply to Release Notes. Mandatory section

Reviewers

@QilongTang Not sure if these can get reviewed

FYIs

@aparajit-pratap @achintyabhat

@Copilot Copilot AI review requested due to automatic review settings June 12, 2025 00:51
Copy link
Contributor

@Copilot 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

This PR introduces targeted performance and memory optimizations in the graph execution engine, focusing on hot paths and reducing allocations.

  • Removed LINQ in critical loops and replaced with manual iterations or spans
  • Added methods to cache and reuse interpreters and to set symbol values while retrieving previous values
  • Refactored heap and DSObject allocation to consolidate metadata handling

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
RuntimeMemory.cs New SetSymbolValueAndGetPreviousValue method with incomplete XML docs
MirrorData.cs Switched from static to instance methods; new ctor overloads
JILFunctionEndPoint.cs Cached Interpreter instance instead of per-call instantiation
CallSite.cs Changed replication-instruction lists to ReadOnlySpan
CLRObjectMarshaler.cs Removed LINQ from type-check; simplified StackValue handling
CLRFFIFunctionPointer.cs Cached parameter arrays and marshaler instances
Heap.cs Introduced AllocatePointerInternal for metadata-aware allocation
Executive.cs Added Reset method; symbol-node lookup caching
DSObject.cs New DSObject ctor accepting metadata
AssociativeGraph.cs Replaced LINQ with indexed loops; unsafe index use in IsSSANode
Comments suppressed due to low confidence (5)

src/Engine/ProtoCore/RuntimeMemory.cs:189

  • The new XML documentation for SetSymbolValueAndGetPreviousValue is empty. Please provide meaningful <summary>, <param> and <returns> descriptions.
/// <summary>

src/Engine/ProtoCore/Reflection/MirrorData.cs:191

  • Changing GetData from static to instance breaks its previous static contract. Ensure callers are updated and document this API change.
internal object GetData(StackValue sv, RuntimeCore runtimeCore)

src/Engine/ProtoCore/DSASM/Executive.cs:2324

  • [nitpick] The field cachesymbolIndex has inconsistent casing. Rename to cacheSymbolIndex to match cacheBlockID and cacheClassIndex.
private int cachesymbolIndex = -1;

src/Engine/ProtoCore/Reflection/MirrorData.cs:71

  • The new constructor overload lacks XML doc comments. Please document its parameters (i, m) and intended usage.
/// <summary>

src/Engine/ProtoCore/Lang/JILFunctionEndPoint.cs:40

  • Reusing a single Interpreter instance (mInterpreter) across calls may introduce thread-safety issues. Consider making interpreter usage thread-local or synchronizing access.
private void Init(RuntimeCore runtimeCore)

Comment on lines +1503 to 1504
var firstNode = updateNodeRefList[0].nodeList[0];
return firstNode != null && firstNode.nodeType == UpdateNodeType.Symbol && firstNode.symbol.isSSATemp;
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

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

Accessing updateNodeRefList[0].nodeList[0] without checking for an empty list can throw IndexOutOfRangeException. Validate both lists before indexing or revert to a safe lookup.

Suggested change
var firstNode = updateNodeRefList[0].nodeList[0];
return firstNode != null && firstNode.nodeType == UpdateNodeType.Symbol && firstNode.symbol.isSSATemp;
if (updateNodeRefList.Count > 0 && updateNodeRefList[0].nodeList.Count > 0)
{
var firstNode = updateNodeRefList[0].nodeList[0];
return firstNode != null && firstNode.nodeType == UpdateNodeType.Symbol && firstNode.symbol.isSSATemp;
}
return false;

Copilot uses AI. Check for mistakes.

saintentropy and others added 4 commits June 24, 2025 00:08
(cherry picked from commit 9f5e99050e6a5dfd732a0e641cc4e987a2d50c32)
(cherry picked from commit 1a42ed02775abe7823a3995a05080aaf184baef9)
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