Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of linerange #629

Merged
merged 12 commits into from Feb 26, 2022
Merged

Improve performance of linerange #629

merged 12 commits into from Feb 26, 2022

Conversation

Krock21
Copy link
Contributor

@Krock21 Krock21 commented Aug 5, 2020

I found that the bandit is running very slow on the file long_set.py
I added some caching for linerange function

Feel free to comment and propose a better solution

See time measurements down below

Copy link
Member

@ericwb ericwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please attach the file long_set.py, so I can compare as well for the review? Thanks!

@Krock21
Copy link
Contributor Author

Krock21 commented Dec 20, 2020

Can you please attach the file long_set.py, so I can compare as well for the review? Thank

Sure!
https://github.com/Krock21rus/bandit/blob/cache_linerange/examples/long_set.py

@Krock21 Krock21 requested a review from ericwb December 23, 2020 21:03
@Krock21
Copy link
Contributor Author

Krock21 commented Jan 9, 2021

Ok, I measured it again:
Pure version from master:
command():

git clean -d -f -x && cp ~/long_set.py examples/long_set.py && virtualenv -p python3 bandit-env && source bandit-env/bin/activate && pip3 install -r requirements.txt && python3 setup.py install && time ./bandit-env/bin/bandit examples/long_set.py

result:

Run started:2021-01-09 12:40:26.826760
Test results:
	No issues identified.
Code scanned:
	Total lines of code: 7278
	Total lines skipped (#nosec): 0
Run metrics:
	Total issues (by severity):
		Undefined: 0.0
		Low: 0.0
		Medium: 0.0
		High: 0.0
	Total issues (by confidence):
		Undefined: 0.0
		Low: 0.0
		Medium: 0.0
		High: 0.0
Files skipped (0):

real	0m57,304s
user	0m56,296s
sys	0m0,478s

updated version from Krock21rus:cache_linerange(this pull request)
Just checkout branch and run it, long_set.py is already added to examples

command:

git clean -d -f -x && virtualenv -p python3 bandit-env && source bandit-env/bin/activate && pip3 install -r requirements.txt && python3 setup.py install && time ./bandit-env/bin/bandit examples/long_set.py

result:

Run started:2021-01-09 12:43:17.356068
Test results:
	No issues identified.
Code scanned:
	Total lines of code: 7278
	Total lines skipped (#nosec): 0
Run metrics:
	Total issues (by severity):
		Undefined: 0.0
		Low: 0.0
		Medium: 0.0
		High: 0.0
	Total issues (by confidence):
		Undefined: 0.0
		Low: 0.0
		Medium: 0.0
		High: 0.0
Files skipped (0):

real	0m1,000s
user	0m0,982s
sys	0m0,008s

57s -> 1s on a single long_set with 7276 'a' elements

Copy link
Member

@ericwb ericwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very noticeable improvement. Nicely done. However, I do think most of this linerange() func becomes redundant with Python 3.8 included end_lineno on nodes.

This was referenced Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants