Skip to content

[BUG] Faraday logging bodies is memory intensive when passing a large PDF #562

@taylars

Description

@taylars

Basic checks

  • I searched existing issues - this hasn't been reported
  • I can reproduce this consistently
  • This is a RubyLLM bug, not my application code

What's broken?

When passing in a large PDF, faraday and pretty print use a significant amount of memory for logging. When running a memory profile, you can see below that faraday and pp use 66MB of memory:

allocated memory by gem (bytes)
-----------------------------------
  33451488  pp-0.6.3
  33414027  faraday-2.14.0

However, if I disable body logging for faraday, that drops to a negligible amount:

allocated memory by gem (bytes)
-----------------------------------
   113466  faraday-2.14.0
        1176  pp-0.6.3

How to reproduce

  1. Create an ActiveStorage object for a large PDF
  2. Call OpenAI with that PDF

Expected behavior

This logging should not take such a large amount of memory.

What actually happened

Logging uses a significant amount of memory (over 10x the size of the PDF)

Environment

  • Ruby version: 3.4.2
  • RubyLLM version: 1.9.1
  • Provider: OpenAI

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions