Skip to content
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

More benchmarks for natives #124

Merged
merged 153 commits into from
May 29, 2024
Merged

More benchmarks for natives #124

merged 153 commits into from
May 29, 2024

Conversation

0xd34df00d
Copy link
Contributor

PR checklist:

  • Test coverage for the proposed changes
  • PR description contains example output from repl interaction or a snippet from unit test output
  • Any changes that could be relevant to users have been recorded in the changelog

Additionally, please justify why you should or should not do the following:

  • Confirm replay/back compat
  • Benchmark regressions
  • (For Kadena engineers) Run integration-tests against a Chainweb built with this version of Pact

@@ -97,7 +97,8 @@ lookupFqName fqn =
getDefCap :: (MonadEval b i m) => i -> FullyQualifiedName -> m (EvalDefCap b i)
getDefCap info fqn = lookupFqName fqn >>= \case
Just (DCap d) -> pure d
_ -> failInvariant info "Expected DefCap"
Just _ -> failInvariant info "Expected DefCap"
_ -> failInvariant info "Expected DefCap; got nothing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I agree, we need a better ADT for invariant failures.

@@ -1984,7 +2065,7 @@ coreBuiltinRuntime = \case
CoreDefineNamespace -> coreDefineNamespace
CoreDescribeNamespace -> coreDescribeNamespace
CoreZkPairingCheck -> zkPairingCheck
CoreZKScalarMult -> zkScalaMult
CoreZKScalarMult -> zkScalarMult
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we are now no longer multiplying Scalas :)

@@ -1656,8 +1735,10 @@ coreDescribeNamespace :: (CEKEval step b i m, MonadEval b i m) => NativeFunction
coreDescribeNamespace info b cont handler _env = \case
[VString n] -> do
pdb <- viewEvalEnv eePactDb
chargeGasArgs info $ GRead $ sizeOf SizeOfV0 n
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HMM. This does not seem right. Why are we charging gas on the size of the name of the namespace?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should charge for an object with the name + two guards (user and admin one)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace itself is only charged if it's found by name. Hence to prevent undercharging in case the namespace isn't found, it's easier and less error-prone to just charge for the mere fact of looking up the name in the DB. After it's found, it's also charged for the namespace object with its guards.

pact/Pact/Core/IR/Eval/CoreBuiltin.hs Show resolved Hide resolved
pact/Pact/Core/IR/Eval/CoreBuiltin.hs Outdated Show resolved Hide resolved
pact/Pact/Core/Gas/TableGasModel.hs Outdated Show resolved Hide resolved
pact/Pact/Core/IR/Eval/CoreBuiltin.hs Show resolved Hide resolved
-- THIS CANNOT MAKE IT TO PROD
renderPactValue :: PactValue -> T.Text
renderPactValue = T.pack . show . Pretty.pretty
-- Todo: this is kinda hacky
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this change.

That said: you already gassed Show. I think we could reuse your Show gas for this. After all, format is essentially just Show with string splicing.

[VString s] ->
checkLen info s *> doBase info cont handler 10 s
[VString s] -> do
chargeGasArgs info $ GStrOp $ StrOpLength $ T.length s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious what we're charging for here? Shouldn't we be charging for parsing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, updated

Right bs -> returnCEKValue cont handler $ VInteger (bsToInteger bs)
| base >= 2 && base <= 16 -> checkLen info s *> doBase info cont handler base s
| base == 64 -> do
chargeGasArgs info $ GStrOp $ StrOpLength $ T.length s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, I believe we should be charging for parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, updated

. (esLoaded.loAllLoaded %~ M.insert fqn dfn)
where
fqn = mkGasModelFqn name
dkind = case dfn of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call defKind from Pact.Core.IR.Term

@0xd34df00d 0xd34df00d merged commit abc917e into master May 29, 2024
3 checks passed
@0xd34df00d 0xd34df00d deleted the gr/gas-bench-natives-b1 branch May 29, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants