# Optimizing OPA performance: From arrays to objects

DevFeed: [Optimizing OPA performance: From arrays to objects](<https://devfeed.tech/articles/optimizing-opa-performance-from-arrays-to-objects-22577.md>)

Original publisher: [Read original article](<https://medium.com/capital-one-tech/optimizing-opa-performance-from-arrays-to-objects-a3c966acdaa5?source=rss----3db3a67cb648---4>)

Author: Capital One Tech

Published: 2026-07-07T14:25:30Z

Content type: tutorial

Language: en

Sources: [Capital One Tech](<https://devfeed.tech/sources/capital-one-tech.md>)

Topics: [opa](<https://devfeed.tech/topics/opa.md>), [Open Policy Agent](<https://devfeed.tech/topics/open-policy-agent.md>), [rego](<https://devfeed.tech/topics/rego.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [Algorithms, Complexity](<https://devfeed.tech/topics/algorithms-complexity.md>)

Tags: [algorithms](<https://devfeed.tech/tags/algorithms.md>), [cloud-native](<https://devfeed.tech/tags/cloud-native.md>), [data-structures](<https://devfeed.tech/tags/data-structures.md>), [kubernetes](<https://devfeed.tech/tags/kubernetes.md>), [opa](<https://devfeed.tech/tags/opa.md>), [open-policy-agent](<https://devfeed.tech/tags/open-policy-agent.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [performance-tuning](<https://devfeed.tech/tags/performance-tuning.md>), [rego](<https://devfeed.tech/tags/rego.md>), [software-development](<https://devfeed.tech/tags/software-development.md>), [software-engineering](<https://devfeed.tech/tags/software-engineering.md>), [software-supply-chain](<https://devfeed.tech/tags/software-supply-chain.md>)

## AI overview

This article explains how to improve Open Policy Agent performance by choosing appropriate data structures for Rego policies. It focuses on replacing nested arrays with keyed objects to avoid inefficient array traversal when evaluating large datasets.

## Source excerpt

Achieve 99% faster Rego policy execution through optimization. Note: This post focuses on one aspect of performance tuning Rego policies and datasets evaluated by OPA-arrays vs. objects. The Rego Style Guide and Regal Rego linter are very helpful resources for learning Rego best practices and avoiding code smells in Rego policies. There is also the OPA performance tuning documentation. In 2018, I started using open policy agent (OPA) as a solution for controlling and preventing unwanted behaviors in our Kubernetes Clusters. OPA, along with Kubernetes Dynamic Admission Control, provided a means to build preventive controls. Since then, I have worked with several PaC solutions. I have always stayed close to the OPA tool set because of how well it supports multiple use cases. OPA is domain agnostic and can be used with virtually any use case, as long as you supply the correct data and policies. To that end, OPA use cases have expanded throughout several technical disciplines, such as cloud-native computing and software supply chain management. OPA performance engineering OPA enables us to unify PaC solutions across multiple use cases and systems, using the same languages and tools. However, there is always room for improvement and performance engineering policies and the execution thereof. In addition, optimizing data that policies evaluate and mutate should be part of our focus when we deliver OPA-based solutions. Recently I was asked to help with OPA performance issues. I made several recommendations, but I overlooked one simple and glaring issue: the poor performing policy was processing a large data set using nested-arrays, instead of the best practice of using keyed-objects. Later, something was bothering me about my interaction and I realized that while I gave decent architectural level advice, I completely missed the best engineering advice. Rego policies and data should be optimized just like other algorithms and relative data, and part of that optimization is