-
Notifications
You must be signed in to change notification settings - Fork 77
Experiment: improve docs performance #2524
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: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @ohmayr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the performance of documentation generation by optimizing the Markdown-to-RST conversion process. It introduces a multi-tiered approach, prioritizing a new, fast, pure-Python converter for most common cases and leveraging a caching mechanism. The external Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This PR aims to improve documentation generation performance by introducing a custom, pure-Python Markdown-to-RST converter for common cases, which is a good strategy. While reviewing the changes, I found a few areas for improvement. I've identified a bug in heading conversion that can produce invalid RST, an omission in handling numbered lists, and a formatting inconsistency. Most critically, the new logic is not covered by tests, and the changes appear to break existing tests. Please see my detailed comments for suggestions on how to fix these problems. Adding a robust test suite will be essential to ensure the correctness of this performance optimization.
| # Cache for the few complex items we actually send to pandoc | ||
| _RAW_RST_CACHE: Dict[str, str] = {} | ||
|
|
||
| def _tuned_fast_convert(text: str) -> Optional[str]: |
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.
This new conversion logic in _tuned_fast_convert is a critical part of the performance improvement, but it lacks unit tests. Additionally, the changes in the rst function appear to break the existing tests in tests/unit/utils/test_rst.py (e.g., test_rst_formatted), as they now bypass the mocked pypandoc.convert_text call.
It's crucial to:
- Add comprehensive unit tests for
_tuned_fast_convertcovering all the regex conversions and edge cases (links, code blocks, headings, lists). - Update the existing tests for the
rstfunction to reflect the new logic, including caching and the fast-path converter.
Without proper tests, it's hard to verify the correctness of these performance optimizations and prevent future regressions.
| converted = re.sub(r"^# (.*)$", r"\1\n" + "=" * 10, converted, flags=re.MULTILINE) | ||
| converted = re.sub(r"^## (.*)$", r"\1\n" + "-" * 10, converted, flags=re.MULTILINE) |
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.
The RST specification requires that heading underlines are at least as long as the heading text. Using a fixed length of 10 characters for the underline can result in invalid RST for headings longer than 10 characters, which would break the documentation build. The replacement in re.sub should be a function that calculates the correct underline length based on the matched heading text.
| converted = re.sub(r"^# (.*)$", r"\1\n" + "=" * 10, converted, flags=re.MULTILINE) | |
| converted = re.sub(r"^## (.*)$", r"\1\n" + "-" * 10, converted, flags=re.MULTILINE) | |
| converted = re.sub(r"^# (.*)$", lambda m: f"{m.group(1)}\n{'=' * len(m.group(1))}", converted, flags=re.MULTILINE) | |
| converted = re.sub(r"^## (.*)$", lambda m: f"{m.group(1)}\n{'-' * len(m.group(1))}", converted, flags=re.MULTILINE) |
| converted = re.sub(r"^## (.*)$", r"\1\n" + "-" * 10, converted, flags=re.MULTILINE) | ||
|
|
||
| # F. LISTS: Markdown (- item) needs a preceding newline for RST. | ||
| converted = re.sub(r"(\n[^-*].*)\n\s*([-*] )", r"\1\n\n\2", converted) |
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.
The regex for list conversion only handles unordered lists starting with - or *. It does not handle numbered lists (e.g., 1. item). This will cause numbered lists to be rendered incorrectly, as they also require a blank line preceding them in RST. The logic should be updated to also handle numbered lists.
| if "::" in raw_rst or ".. code" in raw_rst: | ||
| answer = raw_rst.replace("\n", f"\n{' ' * indent}") | ||
| else: | ||
| answer = wrap(raw_rst, indent=indent, offset=indent, width=width - indent) |
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.
The call to wrap here uses offset=indent, while the "Super Fast Path" on line 73 uses offset=indent + 3. This inconsistency can lead to different wrapping for plain text versus text with markdown, resulting in inconsistent formatting. For consistent output, the offset should be the same in both places.
| answer = wrap(raw_rst, indent=indent, offset=indent, width=width - indent) | |
| answer = wrap(raw_rst, indent=indent, offset=indent + 3, width=width - indent) |
This PR improves the docs generation performance.