Improve chart speed
Issue #989
new
When plotting a chart of 1,000,000 studies with the “Remove category whitespace padding“ it takes about 8 seconds to prepare the Pandas dataframe.
This section of chart_functions.py
(from line 156) removes any leading and trailing whitespace and also removes any multiple spaces:
if data_point_name_remove_whitespace_padding:
df[field_dict["names"]] = df[field_dict["names"]].apply(
lambda x: x.str.strip().replace("\s+", " ", regex=True)
)
Replacing it with this code reduces the time to 5 seconds:
if data_point_name_remove_whitespace_padding:
# Remove any spaces at start and end of each entry
df[field_dict["names"]] = df[field_dict["names"]].apply(lambda x: x.str.strip())
# Remove any multiple spaces
df[field_dict["names"]] = df[field_dict["names"]].apply(lambda x: x.str.replace("\s+", " ", regex=True))
It’s the same as the first code snippet, but the strip()
is run first, and then the replace()
.