Skip to content

Option code optimizer #71

@declard

Description

@declard

Imagine there is a higly loaded application making heavy usage of the Option types, and there is a monadic code with all those FlatMaps and Maps, or even worse - linq syntax expression, invoked in a loop somewhere. That brings pressure on the GC as closures and anonymous objects are continiously created.

What if

(a, b, c) =>
    from aprime in a
    from bprime in b
    from cprime in c
    where Predicate(aprime, cprime)
    select Combine(aprime, bprime, cprime)

transformed automagically into something like

(a, b, c) =>
{
    if (!a.HasValue) return default;
    var aprime = a.GetValue();
....
    if (!Predicate(aprime, cprime) return default;
    return Combine(aprime, bprime, cprime);
}

when passing it as an expression to a special function?

I understand this might be not a frequent case and one would say "use low-level things in this case", but anyway, should an optimized Option code generation be considered as an appropriate feature for this library?

I have my own small library (which nobody really knows about) with maybe, either, CPS, collection extensions and so on, and there's a code there for doing what I've just described (not published anywhere yet), I decided it would be more productive to contribute here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions