Lazy load validation.security on import of datadog_checks.checks#23936
Draft
jinh-labs wants to merge 1 commit into
Draft
Lazy load validation.security on import of datadog_checks.checks#23936jinh-labs wants to merge 1 commit into
jinh-labs wants to merge 1 commit into
Conversation
Importing datadog_checks.checks always pulls in the security module (datadog_checks.base.utils.models.validation.security), which accounts for about 1 MiB of memory, even for checks that never use it. Now it's lazy loaded, so the security module is only loaded on use. That saves about 1 MiB for checks that don't need it, with no change for the ones that do.
Contributor
|
Contributor
Validation Report
Run Passed validations (20)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes the
validationpackage lazy using the samelazy_loader.attach_stubpattern already applied to otherbasesubpackages (#19838), soimport datadog_checks.checksno longer loadsvalidation.securityat import time (which pulls indataclasses).Motivation
Follow-up to the 9 MiB / instance sub-interpreter overhead investigation (https://datadoghq.atlassian.net/wiki/spaces/ARUN/pages/6797659760/), specifically the question "how much of the
import datadog_checks.checkscost can be lazy-loaded?"Findings:
requests, OpenMetrics,ddtrace, are already lazy (Add lazy import mechanism to the base package #19838 / Refactor imports #19845), and correctly stay deferred atrun(). Those were real wins.security(+dataclasses) accounts for ~1 MiB.Honest scope: please read before reviewing
subinterp_mem.cbenchmark), this defers ~1 MiB: the import drops from ~5.7 MiB to ~4.6 MiB (sub-interpreter infra, ~2.6 MiB, is unaffected).check.run()->load_configuration_models, which builds the config-validation context and reloadssecurityregardless of whether the check has config models. So the saving is undone after the first check run and net savings on a running idle instance is approximately 0.snmpandtokumx, are deprecated/unsupported.So this only moves the import-phase number, not running instances.
Validation
Review checklist (to be filled by reviewers)
qa/requiredif this PR needs QA validation, orqa/skip-qaif it does not. Exactly one of the two is required.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged