Skip to content

perf: avoid allocations in object.get#8729

Open
anderseknert wants to merge 1 commit into
open-policy-agent:mainfrom
anderseknert:zero-alloc-object-get
Open

perf: avoid allocations in object.get#8729
anderseknert wants to merge 1 commit into
open-policy-agent:mainfrom
anderseknert:zero-alloc-object-get

Conversation

@anderseknert
Copy link
Copy Markdown
Member

This change removes the 1-2 heap allocations previously made per call to the object.get built-in function.

Also:

  • Slightly tweak builtins.<Type>Operand functions to have them pass the inlining threshold score of 80 — they would previously all score at 81!

This change removes the 1-2 heap allocations previously made per call
to the `object.get` built-in function.

Also:
- Slightly tweak `builtins.<Type>Operand` functions to have them pass
  the inlining threshold score of 80 — they would previously all score
  at 81!

Signed-off-by: Anders Eknert <anders.eknert@apple.com>
Comment thread v1/topdown/object.go
func builtinObjectGet(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error {
object, err := builtins.ObjectOperand(operands[0].Value, 1)
// silly micro optimization: initial ref to last item avoids
// later bounds checks as 1 and 0then known to be valid indices
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// later bounds checks as 1 and 0then known to be valid indices
// later bounds checks as 1 and 0 then known to be valid indices

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.

2 participants