Profiling has shown that the env_secrets() function can consume a surprising amount of dbt's running (parsing) time (>5% in some scenarios). This is because it checks all environment variables for secrets every time an event is fired. Since environment variables rarely change in practice, most of this time is being wasted. Instead of re-computing the secrets on every event, we should do this once after a dbt command starts, and cache the results in the execution context for that command.
Acceptance criteria
The env_secrets() function no longer consumes a significant portion of dbt's running time
Secrets are comupted once per dbt invocation and stored in the invocation's execution context
Could consider managing this caching in the task context vars - this could potentially handle resetting the cache between programmatic invocations by default - if it is called within the context manager.
Housekeeping
Short description
Profiling has shown that the env_secrets() function can consume a surprising amount of dbt's running (parsing) time (>5% in some scenarios). This is because it checks all environment variables for secrets every time an event is fired. Since environment variables rarely change in practice, most of this time is being wasted. Instead of re-computing the secrets on every event, we should do this once after a dbt command starts, and cache the results in the execution context for that command.
Acceptance criteria
Impact to Other Teams
None.
Will backports be required?
No.