# 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: article

Language: en

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

Topics: [Open Policy Agent](<https://devfeed.tech/topics/open-policy-agent.md>), [performance-engineering](<https://devfeed.tech/topics/performance-engineering.md>), [Algorithms](<https://devfeed.tech/topics/algorithms.md>), [computational complexity](<https://devfeed.tech/topics/computational-complexity.md>), [Data Management](<https://devfeed.tech/topics/data-management.md>), [data-engineering](<https://devfeed.tech/topics/data-engineering.md>), [anchore](<https://devfeed.tech/topics/anchore.md>)

Tags: [algorithms](<https://devfeed.tech/tags/algorithms.md>), [arrays](<https://devfeed.tech/tags/arrays.md>), [cloud-native](<https://devfeed.tech/tags/cloud-native.md>), [data](<https://devfeed.tech/tags/data.md>), [datasets](<https://devfeed.tech/tags/datasets.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [faster](<https://devfeed.tech/tags/faster.md>), [kubernetes](<https://devfeed.tech/tags/kubernetes.md>), [large](<https://devfeed.tech/tags/large.md>), [nested](<https://devfeed.tech/tags/nested.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>), [optimizing](<https://devfeed.tech/tags/optimizing.md>), [performance](<https://devfeed.tech/tags/performance.md>), [performance-engineering](<https://devfeed.tech/tags/performance-engineering.md>), [performance-tuning](<https://devfeed.tech/tags/performance-tuning.md>), [policies](<https://devfeed.tech/tags/policies.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>), [solution](<https://devfeed.tech/tags/solution.md>)

## AI overview

In an SBOM risk-enrichment example, replacing a 1.9-million-row EPSS array with a CVE-keyed object let Rego use direct object access instead of repeatedly traversing and comparing array entries. The JSON shrank from 46 MB to 20 MB. Processing 124 vulnerability profiles fell from about 48 seconds to 0.654 seconds (about 98% faster); query evaluation dropped from about 26 seconds to 5 milliseconds (about 99%). The article uses OPA's CLI profiler and metrics to locate the bottleneck, then transforms the data with jq and updates the policy to look up EPSS values by CVE ID. It notes that bundle loading and data parsing improved more modestly, and that further policy optimizations may be possible.

## 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