dadhi / dadhi/FastExpressionCompiler
[Idea] Batch the nested lambda compilation together
- Dominant language
- C#
- Stars
- 1.4k
- Forks
- 94
- PR merge metrics
- No merged PRs in 30d
Description
> Migrated from the DryIoc https://github.com/dadhi/DryIoc/issues/467
The #465 showing the most time of the compilation is spent on the creating the `DynamicMethod` and actually compiling this.
Some delegate expressions are small like `(IResolverContext r) => new A()`, so the most time is spent on the wrapping it in the compilation unit, and we have many of these.
To improve the time and memory consumption, the idea is to batch those lambdas together like below and compile them as one `DynamicMethod`:
```cs
byte tag = 0;
(IResolverContext r) => tag switch {
0 => new A(),
1 => new B(),
2 => new C(new X(), new Y())
//... etc.
}
```
The `tag` is something that can be set in the lambda closure object. In order to do so, I will create an open delegate via `dynamicMethod.CreateDelegate(DelegateType, null)` and pass the preconfigured closure as its first argument.
**Pros:**
- Single compilation unit instead of many with faster compile time and less memory footprint
**Cons:**
- Slight delegate invocation performance decrease (only for the subset of the cases and only about the nested lambdas)
- More complex implementation logic
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.