Skip to content

Conversation

thewildofficial
Copy link

  • Added FastAPI for better concurrency
  • Implement asynchronous job processing and benchmarking for puzzle generation
  • Refactor puzzle generation to remove process pool executor and run synchronously
  • fix: Resolve API errors, add gitignore, and update README

AmoghRao21 and others added 4 commits April 22, 2025 23:19
- Add missing 'import asyncio' to api.py to fix background task NameError.
- Create .gitignore to exclude build artifacts, venv, and output.
- Update README.md with detailed build/run instructions for Rust extension and API.
@thewildofficial
Copy link
Author

thewildofficial commented Apr 22, 2025

Title: Refactor Core Logic with Rust Solver, API, and Benchmarking

Description:

This pull request introduces a significant refactoring of the core puzzle generation logic. The primary goal was to enhance performance and scalability by implementing the computationally intensive solving part in Rust and integrating it into the existing Python application via an updated API. This effort also included establishing a benchmarking process and resolving build/runtime issues encountered during integration.

Key Changes:

  1. Rust Solver Implementation: Developed a new Rust library (wordgrid_solver) containing the core word grid solving algorithm for improved performance.
  2. Python Integration: Integrated the Rust library into the Python application using pyo3 and maturin, allowing Python code to call the high-performance Rust functions.
  3. API Refactoring: Updated the FastAPI application (api.py) to utilize the new Rust solver. Puzzle generation is now handled asynchronously via background tasks for better responsiveness.
  4. Benchmarking: Introduced a script (benchmark.py) to measure the throughput and latency of the puzzle generation API, validating the performance improvements from the Rust integration.

Challenges Addressed & Fixes Implemented:

To ensure the stability and correctness of the refactored system, the following issues were resolved:

  • Build Stability: Ensured the Rust extension builds reliably within the correct Python virtual environment using maturin develop.
  • Server Startup: Addressed uvicorn path issues (using python -m uvicorn ...) and implemented handling for potential port conflicts (port 8000).
  • API Runtime: Fixed a NameError in the asynchronous background task (api.py) by adding import asyncio.
  • Dependencies: Confirmed all necessary dependencies are installed via requirements.txt.

Verification:

  • Build: The wordgrid_solver Rust extension builds successfully.
  • Server: The FastAPI server starts reliably.
  • Functionality: API endpoints (/generate, /status/{task_id}) operate correctly, leveraging the Rust solver. All pytest tests pass.
  • Performance: Benchmarking (benchmark.py -n 4) validates the effectiveness of the Rust solver, demonstrating consistent and improved performance:
    • Throughput: ~12.28 jobs/second
    • Average Latency: ~0.27 seconds

Outcome:

This refactoring successfully replaces the previous puzzle generation logic with a significantly faster and more robust Rust-based solution. The application is stable, buildable, and demonstrably more performant, providing a strong foundation for future development.

Note: Minor warnings related to deprecated features in Pydantic and PyPDF2 persist in test outputs but do not impact current functionality. These can be addressed in subsequent updates.

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