Skip to content

[FEAT]: Make PDF Processing Faster with Template Caching #313

@Cubix33

Description

@Cubix33

📝 Description

Right now, FireForm reads and calculates the layout of a PDF form from scratch every single time it runs. If a fire department fills out the exact same "Incident Report" 100 times a day, our system wastes time and processing power re-reading the same blank form 100 times.

💡 Rationale

We should save (or "cache") the blank form in the system's memory the very first time we see it. The next 99 times, FireForm will skip the slow hard-drive reading process and load the form instantly from memory. This will make the system much faster and allow it to handle more forms at once.

🛠️ Proposed solution

We can do this by adding a simple memory dictionary to our PDF filler code.

  • Create the Cache: Add a dictionary (self._template_cache = {}) inside the Filler class to store the raw bytes of the PDFs.
  • Update PDF Loading: In the fill_form function, check if the PDF is already in the cache.
    • If it's new, read the file from the hard drive and save it to the cache.
    • If it's already saved, load it instantly using PdfReader(fdata=...).
  • Reset LLM Memory: Ensure self._json is reset to an empty dictionary {} at the start of main_loop in src/llm.py. This prevents older answers from crashing the system when doing multiple fast runs.

✅ Acceptance Criteria

  • The "Double Run" Test: If we send the exact same form to the system twice in a row, the terminal prints [LOG] Template Cache Hit! on the second run.
  • No Crashes: The system successfully processes the second run without throwing an AttributeError or memory state bug.
  • Speed: The second run finishes noticeably faster than the first run because it skips reading the file from the disk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions