Skip to content

Avoid use of startwith in a large loop#58

Open
ben-grande wants to merge 2 commits into
QubesOS:mainfrom
ben-grande:optimize
Open

Avoid use of startwith in a large loop#58
ben-grande wants to merge 2 commits into
QubesOS:mainfrom
ben-grande:optimize

Conversation

@ben-grande

Copy link
Copy Markdown
Contributor

Method 'startwith' adds considerable overhead.


I know it's a cached value, but if >10ms is avoidable, I will take that.

ls-no-cache:2026-06-03T17:41:16.514792+00:00 dom0 qubesd[1566623]:     95895    0.013    0.000    0.013    0.000 {method 'startswith' of 'str' objects}

Method 'startwith' adds considerable overhead.
@marmarek

marmarek commented Jun 7, 2026

Copy link
Copy Markdown
Member

Is your version faster?

@marmarek

marmarek commented Jun 7, 2026

Copy link
Copy Markdown
Member

Specifically, do you see improvement in _load_usb_known_devices time?

@ben-grande

Copy link
Copy Markdown
Contributor Author

Yes. I see improvements.

With startswith:

% grep startswith * | grep 95895
ls-no-cache:2026-06-03T17:41:16.514792+00:00 dom0 qubesd[1566623]:     95895    0.013    0.000    0.013    0.000 {method 'startswith' of 'str' objects}
ls-no-caching:2026-06-04T05:50:19.702238+00:00 dom0 qubesd[1864836]:     95895    0.010    0.000    0.010    0.000 {method 'startswith' of 'str' objects}
ls-no-caching.3:2026-06-04T06:19:08.386369+00:00 dom0 qubesd[1911131]:     95895    0.011    0.000    0.011    0.000 {method 'startswith' of 'str' objects}

% grep _load_usb_known_devices ls-no-cache ls-no-caching{,.3}
ls-no-cache:2026-06-03T17:41:16.514792+00:00 dom0 qubesd[1566623]:        56    0.039    0.001    0.069    0.001 core3ext.py:404(_load_usb_known_devices)
ls-no-caching:2026-06-04T05:50:19.702238+00:00 dom0 qubesd[1864836]:        56    0.027    0.000    0.049    0.001 core3ext.py:404(_load_usb_known_devices)
ls-no-caching.3:2026-06-04T06:19:08.386369+00:00 dom0 qubesd[1911131]:        56    0.035    0.001    0.067    0.001 core3ext.py:404(_load_usb_known_devices)

Without startswith:

% grep _load_usb_known_devices new/*
new/block-ls:2026-06-04T14:44:57.924217+00:00 dom0 qubesd[2571246]:        54    0.024    0.000    0.042    0.001 core3ext.py:404(_load_usb_known_devices)
new/usb-ls:2026-06-04T14:26:41.232351+00:00 dom0 qubesd[2542880]:        56    0.024    0.000    0.042    0.001 core3ext.py:404(_load_usb_known_devices)

@ben-grande ben-grande marked this pull request as ready for review June 7, 2026 18:51
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.

2 participants