-
Notifications
You must be signed in to change notification settings - Fork 54
Performance improvements #65
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: master
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 |
---|---|---|
|
@@ -133,7 +133,9 @@ def _format_timestamp(self, time_): | |
|
||
# ---------------------------------------------------------------------- | ||
def _get_record_fields(self, record): | ||
return {k: self._value_repr(v) for k, v in record.__dict__.items()} | ||
return {k: self._value_repr(v) | ||
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. Nice! 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. Yes, I thought of that. However, subclasses may depend on Another optimization would be to fold the 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. Good point about API breakage. Maybe it's worth for these changes to bump to 3.0 and announce the API changes, so people will notice. |
||
for k, v in record.__dict__.items() | ||
if k not in constants.FORMATTER_RECORD_FIELD_SKIP_LIST} | ||
|
||
# ---------------------------------------------------------------------- | ||
def _value_repr(self, value): | ||
|
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.
Cool, I wasn't aware there is such a difference on lookup performance between lists and sets.
It would be even better if we keep the constant a list here and convert it to a set later in the Formatter class, probably best in its
__init__()
. Then people can still append/remove items as they wish. Even if named constants, they are meant to be customised if necessary.A set is also mutable but with a different API and so users had to adjust their code.
I think converting the list to a set later when creating a Formatter instance, should be ok as this happens only once (or only a few times if the formatter is configured multiple times or on forking or so but still not as often as log records are to be formatted).