New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vectors in UPLC #5816
Vectors in UPLC #5816
Conversation
/benchmark plutus-benchmark:nofib |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'plutus-benchmark:nofib' on '1f9b73f94' (base) and 'f221fec18' (PR) Results table
|
/benchmark plutus-benchmark:marlowe |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'plutus-benchmark:marlowe' on '1f9b73f94' (base) and 'f221fec18' (PR) Results table
|
/benchmark marlowe |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'marlowe' on '1f9b73f94' (base) and 'f221fec18' (PR) Results table
|
/benchmark marlowe |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'marlowe' on '1f9b73f94' (base) and '86bedde12' (PR) Results table
|
@michaelpj I don't think we need vectors in |
Yes, you're right, I was just being overly zealous there. |
We also don't need them in |
86bedde
to
6b57736
Compare
/benchmark plutus-benchmark:nofib |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'plutus-benchmark:nofib' on 'cb91fa6fb' (base) and '6b5773645' (PR) Results table
|
Still looks a bit better. |
6b57736
to
4c4f04b
Compare
plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Core/Instance/Eq.hs
Outdated
Show resolved
Hide resolved
-- s , case _ (C0 ... CN, ρ) ◅ constr i V1 .. Vm ↦ s , [_ V1 ... Vm] ; ρ ▻ Ci | ||
returnCek (FrameCases env cs ctx) e = case e of | ||
(VConstr i args) -> case cs ^? wix i of | ||
-- TODO: handle word/int conversion better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also unsure what to do here. Check if the Integer
is in range, otherwise assume it's a miss?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably fine, because you're only going to get a negative integer if an overflow occurs and that will be caught by (V.?!)
, but this really does need some extensive manual testing.
You could also do what I did in the SmallArray
PR:
VConstr i args
| i < unsafeCoerce (sizeofSmallArray cs) ->
computeCek (transferArgStack args ctx) env . indexSmallArray cs $ unsafeCoerce i
where indexSmallArray
is unsafe lookup and sizeofSmallArray
stupidly returns the length of the array rather than its byte size (man it pisses me off that they literally gave up on the usual camelCasing and stole the name of a C primitive just to assign it a completely different meaning). The logic here is
- we know that the length of the array is a non-negative
Int
, so it's safe tounsafeCoerce
it to aWord64
- once we know that
i
is within the array bounds, it's safe tounsafeCoerce
it to anInt
, unless the array is somehow larger thanfromIntegral (maxBound :: Int) :: Word64
, which isn't something we could deserialize
Please note that I absolutely do not propose to have unsafeCoerce
in there, just explaining the reasoning. Replacing both with fromIntegral
should do the job just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably fine, because you're only going to get a negative integer if an overflow occurs and that will be caught by (V.?!), but this really does need some extensive manual testing.
Yeah no, you can still wrap around to positive again.
I'll add some kind of bounds check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so it can in fact never trigger, because i
is a Word64
and the largest Word64
wraps to only -1
as an Int64
, so can't produce an "apparently good" value. I've left the check in out of caution.
I wanted to write a conformance test for this, but I was blocked by the fact that the parser doesn't do range checks, so in fact already wraps a "too large" number around problematically 😂 but that's a parser bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's beyond my understanding how this can be faster than SmallArray
.
plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Core/Instance/Eq.hs
Outdated
Show resolved
Hide resolved
plutus-core/untyped-plutus-core/src/UntypedPlutusCore/Evaluation/Machine/Cek/Internal.hs
Outdated
Show resolved
Hide resolved
-- s , case _ (C0 ... CN, ρ) ◅ constr i V1 .. Vm ↦ s , [_ V1 ... Vm] ; ρ ▻ Ci | ||
returnCek (FrameCases env cs ctx) e = case e of | ||
(VConstr i args) -> case cs ^? wix i of | ||
-- TODO: handle word/int conversion better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably fine, because you're only going to get a negative integer if an overflow occurs and that will be caught by (V.?!)
, but this really does need some extensive manual testing.
You could also do what I did in the SmallArray
PR:
VConstr i args
| i < unsafeCoerce (sizeofSmallArray cs) ->
computeCek (transferArgStack args ctx) env . indexSmallArray cs $ unsafeCoerce i
where indexSmallArray
is unsafe lookup and sizeofSmallArray
stupidly returns the length of the array rather than its byte size (man it pisses me off that they literally gave up on the usual camelCasing and stole the name of a C primitive just to assign it a completely different meaning). The logic here is
- we know that the length of the array is a non-negative
Int
, so it's safe tounsafeCoerce
it to aWord64
- once we know that
i
is within the array bounds, it's safe tounsafeCoerce
it to anInt
, unless the array is somehow larger thanfromIntegral (maxBound :: Int) :: Word64
, which isn't something we could deserialize
Please note that I absolutely do not propose to have unsafeCoerce
in there, just explaining the reasoning. Replacing both with fromIntegral
should do the job just fine.
Hm, maybe I should try |
98836ee
to
ce76e65
Compare
/benchmark plutus-benchmark:nofib |
Click here to check the status of your benchmark. |
ce76e65
to
4b5d6c1
Compare
/benchmark plutus-benchmark:nofib |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'plutus-benchmark:nofib' on '191103257' (base) and '4b5d6c15a' (PR) Results table
|
I'm unsure if that's a real result or if the changes to |
/benchmark plutus-benchmark:nofib |
1 similar comment
/benchmark plutus-benchmark:nofib |
Click here to check the status of your benchmark. |
Click here to check the status of your benchmark. |
4b5d6c1
to
eb4780a
Compare
/benchmark plutus-benchmark:nofib |
Click here to check the status of your benchmark. |
Comparing benchmark results of 'plutus-benchmark:nofib' on 'd95daf39c' (base) and 'eb4780afd' (PR) Results table
|
Okay, close enough that I do doubt that the constr change was adding anything. We can always do it on its own later. |
Don't look here