pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Azure import try/except over doubles pylint memory usage

Open Jamie- opened this issue 1 year ago • 0 comments

Bug description

We run pylint on a reasonably large codebase, ~900 .py files, ~350k lines. Recently we've needed to support two similar versions of the Azure SDK and as such made the change below in a single file.

from

from azure.mgmt.network.v2022_01_01 import NetworkManagementClient
from azure.mgmt.network.v2022_01_01.models import Resource as NetworkResource

to

try:
    from azure.mgmt.network.v2022_01_01 import NetworkManagementClient
    from azure.mgmt.network.v2022_01_01.models import Resource as NetworkResource
except ImportError:
    from azure.mgmt.network import NetworkManagementClient
    from azure.mgmt.network.v2022_07_01.models import Resource as NetworkResource

This change has increased pylint's run time but more importantly, over doubled resident memory usage! I've tried various combinations of disables and module ignores but cannot get anywhere close to previous figures without reverting the code change. Including attempting to ignore the azure module altogether with --ignored-modules=azure

Numbers below are taken from /usr/bin/time -v python3 -m pylint package1 package2 -f colorized -r n -j 1

Old code:

Elapsed (wall clock) time (h:mm:ss or m:ss): 5:13.65
Maximum resident set size (kbytes): 1589112

New code:

Elapsed (wall clock) time (h:mm:ss or m:ss): 6:30.88
Maximum resident set size (kbytes): 3993300

New code with --ignored-modules=azure:

Elapsed (wall clock) time (h:mm:ss or m:ss): 6:42.64
Maximum resident set size (kbytes): 3994000

To make this more generic, I'm running without a pylintrc file using the latest version from PyPI. This has the side effect of producing masses of warning/error output as usually we have a fair number of disables, however the issue described is still present in this state.

Configuration

No response

Command used

/usr/bin/time -v python3 -m pylint package1 package2 -f colorized -r n -j 1
and
/usr/bin/time -v python3 -m pylint --ignored-modules=azure package1 package2 -f colorized -r n -j 1

Pylint output

n/a

Expected behavior

Original run times and memory usage

Pylint version

pylint 3.0.3
astroid 3.0.3
Python 3.9.18 (main, Aug 25 2023, 13:20:14) 
[GCC 11.4.0]

OS / Environment

Ubuntu 22.04

Additional dependencies

# non-Azure modules removed
azure-common==1.1.28
azure-core==1.26.4
azure-identity==1.12.0
azure-keyvault-certificates==4.7.0
azure-keyvault-secrets==4.7.0
azure-mgmt-automation==1.0.0
azure-mgmt-compute==29.1.0
azure-mgmt-core==1.4.0
azure-mgmt-keyvault==10.2.1
azure-mgmt-monitor==6.0.0
azure-mgmt-network==21.0.1
azure-mgmt-resource==23.0.0
azure-mgmt-storage==21.0.0
azure-storage-blob==12.16.0
msrestazure==0.6.4

Jamie- avatar Feb 16 '24 18:02 Jamie-