Page MenuHomePhabricator

Consider why compositions are significantly faster in the condition of the built-in if function
Closed, ResolvedPublic

Description

See, for example, https://www.wikifunctions.org/view/en/Z15717: is Boolean

There are two implementations. The first is simple Python and tests take around 6000 ms. The second is a composition and tests take around 4000 ms. Similar differences (probably more significant) can be seen using Try this implementation. And yet, this composition is simply defined as: If(is Boolean(Argument reference("Z15717K1")), true, false), so it’s exactly the same code that provides the evaluation. It just requires less time to orchestrate. I’ve no idea why this should be so, but the explanation might help improve orchestration more generally.

Apologies if I’m missing the blindingly obvious!

Event Timeline

We are in the process of gathering more data on the orchestrator, and also have several ideas on how to make it faster, but let's focus on this specific case.

The implementation in https://www.wikifunctions.org/view/en/Z15723 should obviously not exist: it is merely a wrapper around the function itself, and it will kinda confuse the the orchestrator and the interplay for selecting the implementation. The reason it does so is probably due to caching.

Also, completely different thing, I would expect this rather to be implemented as

equal type(type of(K1), Boolean)

instead of the way it is, to be honest.

…The implementation in https://www.wikifunctions.org/view/en/Z15723 should obviously not exist: it is merely a wrapper around the function itself

Thank you for your thoughts. I agree. I created this implementation specifically to demonstrate the improved timing, describing it as “apparently pointless, yet apparently not”. I am rather surprised that its existence has caused no difficulties so far, even when testing with entirely novel values, but I have disconnected it now.

Also, completely different thing, I would expect this rather to be implemented as

equal type(type of(K1), Boolean)

instead of the way it is, to be honest.

Yes. I haven’t been able to find or construct a type-of function yet, let alone type equality. I could do it that way in Python, I suppose, but I was deliberately avoiding using the string “bool”.

type of should be possible with Z803/Value by key. I am not claiming this would be good or efficient, but, in theory, you should be able to get to

equal type(
    type of( K1 ),
    Boolean
)

with

equal type(
    value by key(
        Z39[ Z39K1: Z1K1 ],
        Z18[ Z18K1: K1 ]
    ),
Boolean )

type of should be possible with Z803/Value by key. I am not claiming this would be good or efficient, but, in theory, you should be able to get to

equal type(
    type of( K1 ),
    Boolean
)

with

equal type(
    value by key(
        Z39[ Z39K1: Z1K1 ],
        Z18[ Z18K1: K1 ]
    ),
Boolean )

Thanks for the tip, Cory… I think there’s a bug in Z803. I would expect that it would succeed for any object, since every object has a Z1K1, but it fails for some types, notably strings. (Z500K1
"Call tuples failed in returnOnFirstError. Error: TypeError: responseEnvelope.Z22K1.asJSON is not a function." – which looks like an error handling an error…)

I started to raise a Bug Report for this a while back but never got round to filing it… sorry! I’ll get to it eventually (there are other issues, which is why I never finished it).

Object type equality is https://www.wikifunctions.org/wiki/Z15801

I started to raise a Bug Report for this a while back but never got round to filing it… sorry! I’ll get to it eventually (there are other issues, which is why I never finished it).

✅Done: T363623

Thanks for filing the more specific bug about getting the Z1K1 value.

Regarding the original question: since Z802/if is a built-in function, it is calculated by the orchestrator directly. This means that there is no need to call the evaluator with a potential implementation. Since this outbound call doesn't happen, the built-in would perform faster. At least that's my post-hoc explanation.

We are adding this quarter more metadata to function calls, in the hope to make questions like these easier answerable by you as a community member. The task for that is T363384

I hope this answers the question raised in this task. I will close it for now. Please feel free to reopen if there are more questions or if I answered the wrong quesiton.