-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
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
Speed up validate_entity_id #32137
Speed up validate_entity_id #32137
Conversation
Yes, |
@frenck although your version looks nicer I'd like to point out that it's 11-12% slower than explicit original. |
The original that was provided wasn't complete and didn't pass the tests... Benchmarked with the provided benchmark in this PR, it drops from the original slug solution (10~ seconds on my machine) to a steady 0.48 sec. While passing all tests (which has been extended with more invalid cases). Things that the previous regex didn't do but this one does:
|
So starting with a number Furthermore, there is a test case needed with a double underscore. Reference, the 0.86 release notes: https://www.home-assistant.io/blog/2019/01/23/release-86/ |
Codecov Report
@@ Coverage Diff @@
## dev #32137 +/- ##
==========================================
+ Coverage 94.74% 94.74% +<.01%
==========================================
Files 767 767
Lines 55498 55504 +6
==========================================
+ Hits 52579 52587 +8
+ Misses 2919 2917 -2
Continue to review full report at Codecov.
|
Breaking change
Proposed change
In #32128 @KapJI included a call tree that showed that validate entity ID has horrible performance. And we use that a lot 😱
So I did a quick attempt to rewrite it to use regex. Included a benchmark. On my 2.9 GHz Core i7 machine it goes from 12s to 0.6s.
However, regex is not 100% correct yet. So going to fix that soonish. Just wanted to open PR to get feedback if I am missing entity IDs that need to be valid.
<domain>.<object_id>
can have underscores, but neither can start or end with it.To run benchmark:
hass --script benchmark valid_entity_id
Type of change
Example entry for
configuration.yaml
:# Example configuration.yaml
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale: