Skip to content

fix: reduce repeated regex checks in suggestions engine - #870

Merged
imDarshanGK merged 6 commits into
imDarshanGK:mainfrom
Tuba1809:fix/suggestions-response-time
Jul 28, 2026
Merged

fix: reduce repeated regex checks in suggestions engine#870
imDarshanGK merged 6 commits into
imDarshanGK:mainfrom
Tuba1809:fix/suggestions-response-time

Conversation

@Tuba1809

@Tuba1809 Tuba1809 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Description

Improves the performance of the /suggestions/ endpoint by reducing repeated regex evaluations inside the suggestion engine.

The implementation caches frequently-used regex checks (has_try, has_logging, and has_tests) and reuses those results throughout the analysis process instead of performing identical searches multiple times.

This change is intended to improve response-time consistency while preserving existing behavior.

Related Issue

Fixes #513

Type of change

  • Bug fix
  • New feature / enhancement
  • Documentation update
  • Test addition
  • Refactor

Checklist

  • I have read CONTRIBUTING.md
  • My branch is up to date with main
  • I have run pytest -v and all tests pass
  • I have not introduced duplicate issues or features
  • My PR title follows the format: feat/fix/docs/test: short description
  • I have added tests for new features (Level 2 and 3 issues)
  • No hardcoded secrets or API keys in my code
  • This PR is linked to a GSSoC 2026 issue

Screenshots (if frontend change)

N/A (backend-only change)

Test evidence

python -m pytest backend/tests/test_endpoints.py

=================================
55 passed, 2 warnings in 1.19s
=================================

@Tuba1809
Tuba1809 requested a review from imDarshanGK as a code owner June 6, 2026 08:26
@imDarshanGK imDarshanGK added the invalid Contribution not following assignment rules label Jun 10, 2026
@Tuba1809

Copy link
Copy Markdown
Contributor Author

Hi! Thanks for reviewing my PR.

I noticed the PR has been labeled invalid. Could you please clarify what needs to be changed or why it was marked as invalid? All CI checks are currently passing, so I'd be happy to make any required updates if there's something I missed.

Thanks!

@imDarshanGK imDarshanGK left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@Tuba1809 This PR does not show or verify improvement in /suggestions response time. Please add a simple benchmark or test proving faster performance and keep changes focused on the issue.

@Tuba1809

Tuba1809 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@imDarshanGK Thanks for the feedback! I've added a lightweight performance test that repeatedly exercises run_suggestions() and reports execution time while avoiding brittle timing assertions in CI. The optimization remains focused on reducing repeated regex evaluations and preserving existing behavior.

@imDarshanGK imDarshanGK left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@Tuba1809

Copy link
Copy Markdown
Contributor Author

Hi @imDarshanGK,

I've addressed the requested changes by adding the benchmark and have also fixed the formatting issues reported by CI. All requested updates have been pushed.

Could you please take another look when you have time? Thank you!

@imDarshanGK imDarshanGK removed the invalid Contribution not following assignment rules label Jul 22, 2026

@imDarshanGK imDarshanGK left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@Tuba1809

Copy link
Copy Markdown
Contributor Author

Hi @imDarshanGK, I've addressed the formatting issue reported by the CI by sorting the imports and formatting the affected file according to the project's style. The changes have been pushed, and the checks are rerunning. Could you please take another look when you have a chance? Thank you!

@imDarshanGK imDarshanGK left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@Tuba1809 Please add a short demo showing the performance test execution and its output.

@Tuba1809

Copy link
Copy Markdown
Contributor Author
image Hi @imDarshanGK, thanks for the feedback. I've added the requested performance demo by running the benchmark test locally and attached the execution output. The benchmark shows the optimized run_suggestions() execution (500 iterations completed in 0.0472s), while keeping the test free of brittle timing assertions for CI stability. Please let me know if you'd like any additional benchmarking details. Thank you!

@imDarshanGK imDarshanGK added type:testing Testing related changes and improvements gssoc2026 Official GSSoC 2026 issue type:backend Backend related tasks level:intermediate Intermediate tasks gssoc:approved help wanted Extra attention needed type:feature New feature or request labels Jul 28, 2026
@imDarshanGK
imDarshanGK merged commit fbce0e4 into imDarshanGK:main Jul 28, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved gssoc2026 Official GSSoC 2026 issue help wanted Extra attention needed level:intermediate Intermediate tasks type:backend Backend related tasks type:feature New feature or request type:testing Testing related changes and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix inconsistent response times for /suggestions

2 participants