Skip to content
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

parse_html.activity: about 30% speedup for html parsing #66

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

karlicoss
Copy link
Contributor

I've been reviewing some older takeouts, so had cachew off and parsing was a bit painful... so had a quick look in a profiler and did some optimization

A few optimizations

  • using .find instead of .select is faster since it's not using CSS selectors
  • using SoupStrainer is faster since it only does partial parsing and avoids materializing parts of soup we don't actually use

Measurements on a big Chrome/MyActivity.html file

  • before

    • parsing (up to for loop over outer_divs: 17s
    • processing (everything in for loop): 16s
  • after

    • parsing: 13s
    • procesing: 11s

A few optimizations
- using `.find` instead of `.select` is faster since it's not using CSS selectors
- using `SoupStrainer` is faster since it only does partial parsing and avoids materializing parts of soup we don't actually use

Measurements on a big `Chrome/MyActivity.html` file

- before
  - parsing (up to for loop over `outer_divs`: 17s
  - processing (everything in for loop): 16s

- after
  - parsing: 13s
  - procesing: 11s
@@ -88,7 +88,7 @@ def _serialize_default(obj: Any) -> Any:
if isinstance(obj, Exception):
return {"type": type(obj).__name__, "value": str(obj)}
elif dataclasses.is_dataclass(obj):
d = dataclasses.asdict(obj)
d = dataclasses.asdict(obj) # type: ignore[call-overload] # see https://github.com/python/mypy/issues/17550
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is irrelevant to my changes, must be due to mypy upgrade (apparently is_dataclass refines type to union of dataclass instance and dataclass type...

@purarue
Copy link
Owner

purarue commented Sep 10, 2024

thanks!

will parse against my old takeouts just to make sure nothing breaks and merge in a bit

@karlicoss
Copy link
Contributor Author

I was checking against quite old ones, so hopefully should be ok, but thanks for double checking :)

@purarue purarue merged commit b79f5b3 into purarue:master Sep 11, 2024
7 checks passed
@karlicoss karlicoss deleted the speedup-parse-html branch September 11, 2024 01:37
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