-
Notifications
You must be signed in to change notification settings - Fork 99
data_store: optimise rtconfig serialisation #7313
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
base: 8.6.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,13 +113,31 @@ def listjoin(lst, none_str=''): | |
| for item in lst: | ||
| if item is None: | ||
| items.append(none_str) | ||
| elif any(char in str(item) for char in ',#"\''): | ||
| items.append(repr(item)) # will be quoted | ||
| else: | ||
| items.append(str(item)) | ||
| string = str(item) | ||
| if any(char in string for char in ',#"\''): | ||
| items.append(repr(item)) # will be quoted | ||
| else: | ||
| items.append(string) | ||
| return ', '.join(items) | ||
|
|
||
|
|
||
| def fast_listjoin(lst, none_str=''): | ||
| """Faster variant of listjoin suitable in select cases. | ||
|
|
||
| Compared to listjoin, this does *not*: | ||
| * Rationalise and pretty-format integer lists. | ||
| * Intelligently quote arguments which need quoting. | ||
|
|
||
| Suitable for use in situations where you know the data type of the field | ||
| being joined and the above is of no concern. | ||
| """ | ||
| return ', '.join(( | ||
| none_str if item is None else str(item) | ||
| for item in lst or [None] | ||
| )) | ||
|
Comment on lines
+125
to
+138
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a slimmed down version of
Once for every task in the n-window. According to cProfile, this reduces the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was curious, not much difference constructing the
Strike that (silly me), there would only be one invocation of |
||
|
|
||
|
|
||
| def printcfg(cfg, level=0, indent=0, prefix='', none_str='', | ||
| handle=None): | ||
| """Pretty-print a parsec config item or section (nested dict). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| Also provides default values from the spec as a nested dict. | ||
| """ | ||
|
|
||
| from functools import lru_cache | ||
| import re | ||
| import shlex | ||
| from collections import deque | ||
|
|
@@ -655,12 +656,18 @@ def parsec_validate(cfg_root, spec_root): | |
| return ParsecValidator().validate(cfg_root, spec_root) | ||
|
|
||
|
|
||
| class DurationFloat(float): | ||
| """Duration in floating point seconds, but stringify as ISO8601 format.""" | ||
|
|
||
| def __str__(self): | ||
| class _DurationFloat(float): | ||
| def _str(self): | ||
| return str(Duration(seconds=self, standardize=True)) | ||
|
|
||
| # NOTE: This object is immutable so we cache the value of __str__. | ||
| __str__ = lru_cache(1)(_str) | ||
|
|
||
|
|
||
| # NOTE: Prevent duplicate DurationFloat objects being created for the same | ||
| # duration value. This allows __str__ caching to be effective. | ||
| DurationFloat = lru_cache(None)(_DurationFloat.__call__) | ||
|
Comment on lines
+663
to
+669
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reduces the remaining 2 million calls down to one. This will cache the objects for the lifetime of the Python process in which they are created. This sort of caching is appropriate in circumstances where we wouldn't expect this memory to be released during runtime. If we did want the cache to release memory, we would use |
||
|
|
||
|
|
||
| class Range(tuple): | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an issue of the same type that @dwsutherland spotted in #7306 (comment).
One
str(item)call was being made for each character in the list, resulting in 5x the number ofstrcalls.