Optimize FlatExpression node layout and child reuse semantics#540
Optimize FlatExpression node layout and child reuse semantics#540
Conversation
Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/2a513704-9110-413d-9b3c-70aac362cee3 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/2a513704-9110-413d-9b3c-70aac362cee3 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/2a513704-9110-413d-9b3c-70aac362cee3 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
dadhi
left a comment
There was a problem hiding this comment.
Ci Error: /home/runner/work/FastExpressionCompiler/FastExpressionCompiler/src/FastExpressionCompiler.LightExpression/FlatExpression.cs(1284,16): error CS0103: The name 'Unsafe' does not exist in the current context [/home/runner/work/FastExpressionCompiler/FastExpressionCompiler/src/FastExpressionCompiler.LightExpression/FastExpressionCompiler.LightExpression.csproj::TargetFramework=netstandard2.0]
Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/d837954b-5b7e-496c-ba4f-d57c3df71b15 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Fixed in d4888d2 by replacing the |
|
bs |
FlatExpression was still paying unnecessary space and construction costs: constants used an 8-byte in-place payload, child links only modeled sibling chains, and repeatedly used nodes were eagerly cloned instead of being reused until aliasing actually occurred. This change tightens the node layout and shifts reuse/linking behavior toward first-use ownership plus explicit reference nodes on subsequent reuse.
ExprNode layout
uint _datafor inline constant payload orChildIdx/ChildCountuint _metaforNodeType, flags, and encodedNextIdxExprNodeat 24 bytes while restoring directNextIdx+NodeTypestorageNextIdxwith a non-zero sentinel so index0remains validConstant representation
bool,char,byte/sbyte,short/ushort,int/uint,float, and enums with those underlying sizeslong) boxed/out-of-lineChild linking / reference model
NextIdxChildIdxpoints to the declaration nodeIdentity preservation
Coverage
Example of the new reuse behavior:
This keeps the original declaration node as the primary representation and only materializes an extra node when reuse requires alias-safe linking.