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

[serial] Use a fast path to avoid pattern matching #4255

Merged
merged 1 commit into from
May 28, 2024

Conversation

joerg1985
Copy link
Contributor

I was wondering why a fresh installed openhab instance without addons was creating ~ 1000 int[] instances every 15s.
This fallout is visible when monitoring the free memory of the instance:
image

This PR will add a fast path to avoid this fallout from matching a regex against dozens of not matching directories.

Signed-off-by: Jörg Sautter joerg.sautter@gmx.net

Signed-off-by: Jörg Sautter <joerg.sautter@gmx.net>
@joerg1985 joerg1985 requested a review from a team as a code owner May 28, 2024 15:39
Copy link
Member

@holgerfriedrich holgerfriedrich left a comment

Choose a reason for hiding this comment

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

Good catch, you patch avoids calling the more expensive pattern matching (at least as long as the pattern contains the -.
If I get it correctly, you search for - many times: on the full path and all the parent path strings the way up, as getUsbInterfaceParentPath is called recursively. If you want to avoid that, maybe add a second helper function for the recursive calls, check for the shortcut only once, and then call the helper. WDYT?

@joerg1985
Copy link
Contributor Author

Yes there is room for improvments, but also the danger of over-engineering.
Usually the matching part is at the end and it does not need to go more than 3 parents up the tree, therefore i think it is okay to check every time.

@joerg1985
Copy link
Contributor Author

Ps: in the negative case there is no - at all, so it will check only the full path once and return.

@holgerfriedrich
Copy link
Member

Agreed. Thank you.

@holgerfriedrich holgerfriedrich merged commit 9068ab2 into openhab:main May 28, 2024
5 checks passed
@holgerfriedrich holgerfriedrich added the enhancement An enhancement or new feature of the Core label May 28, 2024
@holgerfriedrich holgerfriedrich added this to the 4.2 milestone May 28, 2024
@wborn
Copy link
Member

wborn commented May 29, 2024

This probably also significantly reduces the CPU consumption by the serial scanner thread? It is the most CPU consuming thread on my system and I still wanted to look into how to reduce this. 🙂

@joerg1985
Copy link
Contributor Author

@wborn the GC threads are taking a lot of time on my installation, so i am locking where the fallout is coming from and try to fix this. This seems to happen also in some libraries too, e.g. jmdns/jmdns#275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants