Skip to content

Improve performance of HEALPix to rectangular by skipping calculation of debug string if it will not be logged - #3352

Open
pleasant-menlo wants to merge 1 commit into
IMAP-Science-Operations-Center:devfrom
pleasant-menlo:3404-logging-optimization
Open

Improve performance of HEALPix to rectangular by skipping calculation of debug string if it will not be logged#3352
pleasant-menlo wants to merge 1 commit into
IMAP-Science-Operations-Center:devfrom
pleasant-menlo:3404-logging-optimization

Conversation

@pleasant-menlo

Copy link
Copy Markdown
Contributor

Change Summary

Overview

When profiling the HEALPix to rectangular conversion, we found a debug log that was taking a significant amount of time.

logger.debug(
f" Mean pixel value at Number of subdivisions: {num_subdivisions}: "
f"array of shape {mean_pixel_value.shape}: {mean_pixel_value}"
)

Since this uses f-strings, it always calculates the string (including stringifying the contents of the subdivided mean_pixel_value data array), even if the logging level does not include debug logs.

We replaced the f-strings in the logger.debug call with %s placeholders and passed the strings in as parameters to avoid building the log string at non-debug log levels.

…alue_from_healpix_map_n_subdivisions only if the string will be logged
Comment on lines +1807 to +1808
f" Mean pixel value at Number of subdivisions: %s: "
f"array of shape %s: %s", num_subdivisions, mean_pixel_value.shape, mean_pixel_value

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this still be an f-string since the only string interpolation is being done within the logger, using the %s and other arguments?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also precommit ruff complains line 1808 is too long, but I presume this is not news :)

@jtniehof

Copy link
Copy Markdown
Collaborator

For context, this is a step towards addressing IMAP-Science-Operations-Center/imap_L3_processing#142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants