Skip to content

Index source locations once per compiler request - #683

Open
Aschenbath wants to merge 1 commit into
danielgtaylor:masterfrom
Aschenbath:fix/comment-source-location-index-682
Open

Aschenbath wants to merge 1 commit into
danielgtaylor:masterfrom
Aschenbath:fix/comment-source-location-index-682

Conversation

@Aschenbath

Copy link
Copy Markdown

Summary

Fixes #682. Index source locations once per input file during a compiler request so rendering each declaration's comments no longer scans the whole file. Preserve the first matching location and the existing formatting of detached, leading, and trailing comments.

The 65 existing proto fixtures produce identical output before and after this change in both standard and Pydantic modes. A synthetic 1,500-field request with 6,001 source locations takes a median 0.29 seconds instead of 6.25 seconds through the complete generator, including Ruff. The 10-field case remains dominated by formatter startup (roughly 70 ms). Core tests: 191 passed; new regression tests also pass on Python 3.9.

This change was developed and independently reviewed with Codex. The full upstream suite was not run; validation used the core/compiler tests and all existing proto fixtures. Ruff 0.12.8 was available locally, rather than the project's pinned ~0.9.1.

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
    • This change has an associated test.
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

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.

Rendering comments can be time consuming.

1 participant