dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.
https://getdbt.com
Apache License 2.0
9.65k stars 1.6k forks source link

[CT-3131] Optimize env_secrets() Function #8672

Open peterallenwebb opened 1 year ago

peterallenwebb commented 1 year ago

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.

MichelleArk commented 12 months ago

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.