executablebooks / rst-to-myst

Convert ReStructuredText to MyST Markdown
https://rst-to-myst.readthedocs.io
MIT License
59 stars 10 forks source link

👌 IMPROVE: Cache directive data loading #36

Closed zsol closed 1 year ago

zsol commented 1 year ago

When repeatedly calling to_docutils_ast on relatively small texts without sphinx support (I'll deal with that in a later PR), the runtime cost is dominated by yaml.safe_load.

Looks like directives.yml isn't expected to change, so it should be safe to load it only once, and cache the result for future invocations.

I ran the following perf test on top of this PR (added an extra flag to to_docutils_ast that controlled clearing the lru_cache):

python -m fastero -s 'from rst_to_myst.parser import to_docutils_ast; docstring=\"This is *emphasized*.\"' -n cached 'to_docutils_ast(docstring, use_sphinx=False, cache_directives=True)' -n uncached 'to_docutils_ast(docstring, use_sphinx=False, cache_directives=False)'

perf

welcome[bot] commented 1 year ago

Thanks for submitting your first pull request! You are awesome! :hugs:
If you haven't done so already, check out EBP's Code of Conduct and our Contributing Guide, as this will greatly help the review process.
Welcome to the EBP community! :tada:

codecov[bot] commented 1 year ago

Codecov Report

Base: 84.44% // Head: 84.48% // Increases project coverage by +0.03% :tada:

Coverage data is based on head (fca087c) compared to base (cb3bc80). Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #36 +/- ## ========================================== + Coverage 84.44% 84.48% +0.03% ========================================== Files 10 10 Lines 1633 1637 +4 ========================================== + Hits 1379 1383 +4 Misses 254 254 ``` | Flag | Coverage Δ | | |---|---|---| | pytests | `84.48% <100.00%> (+0.03%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks#carryforward-flags-in-the-pull-request-comment) to find out more. | [Impacted Files](https://codecov.io/gh/executablebooks/rst-to-myst/pull/36?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) | Coverage Δ | | |---|---|---| | [rst\_to\_myst/parser.py](https://codecov.io/gh/executablebooks/rst-to-myst/pull/36/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks#diff-cnN0X3RvX215c3QvcGFyc2VyLnB5) | `94.68% <100.00%> (+0.23%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.