-
Notifications
You must be signed in to change notification settings - Fork 116
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
[Bug] OmegaConf.structured() extremely slow #622
Comments
@odelalleau , possibly related to the SIMPLE_INTERPOLATION_PATTERN. |
Minimal repro: from omegaconf._utils import get_value_kind
print(
get_value_kind(
"${long_string1xxx}_${long_string2xxx:${a_key}}",
strict_interpolation_validation=True,
)
) Instrumentation (pip install pyinstrument):
|
Limiting the regex to smaller strings and falling back to antlr for bigger one seems like it's fixing it: $ git diff
diff --git a/omegaconf/_utils.py b/omegaconf/_utils.py
index 5a6bcb9..e64a0fd 100644
--- a/omegaconf/_utils.py
+++ b/omegaconf/_utils.py
@@ -408,7 +408,7 @@ def get_value_kind(
if isinstance(value, str) and "${" in value:
if strict_interpolation_validation:
# First try the cheap regex matching that detects common interpolations.
- if SIMPLE_INTERPOLATION_PATTERN.match(value) is None:
+ if len(value) > 20 or SIMPLE_INTERPOLATION_PATTERN.match(value) is None:
# If no match, do the more expensive grammar parsing to detect errors.
parse(value)
return ValueKind.INTERPOLATION
|
Thanks for the report! This bug was introduced with #600 (bad regex design). Fix on its way! |
odelalleau
added a commit
to odelalleau/omegaconf
that referenced
this issue
Mar 19, 2021
odelalleau
added a commit
to odelalleau/omegaconf
that referenced
this issue
Mar 19, 2021
It is more "interesting" (i.e., much slower before the fix)
odelalleau
added a commit
that referenced
this issue
Mar 19, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Calling
OmegaConf.structured(MyDataclass)
is extremely slow with certain dataclasses.That's 27 seconds for the call to
OmegaConf.structured
!I did an ablation study to find that the length of
long_string1xxx
andlong_string2xxx
do matter; longer strings are slower.System information
Using the latest omegaconf installed from master branch.
I was not able to reproduce this with a release version of omegaconf downloaded from pip.
The text was updated successfully, but these errors were encountered: