13 Commits

Author SHA1 Message Date
Timothy Jaeryang Baek d22bb6703f refac 2026-08-10 19:28:21 -06:00
Timothy Jaeryang Baek ff74bfa6a1 refac 2026-08-10 19:25:26 -06:00
Classic298 52cfb02c72 perf: build debug log messages lazily so disabled debug logs cost nothing (#27834)
GLOBAL_LOG_LEVEL defaults to INFO, so every log.debug(...) in the backend is discarded, but the message is built first: 187 call sites interpolate their payload into an f-string before the logging call runs, so the work happens on every request and the result is thrown away. The worst one sits in process_chat_payload and stringifies the whole request body, full conversation history included, once per chat completion.

That one line with DEBUG disabled, CPython 3.12:

| conversation | payload | before   | after   |
| ------------ | ------- | -------- | ------- |
| 4 messages   | 1.2 kB  | 3.4 us   | 0.07 us |
| 20 messages  | 17 kB   | 24.8 us  | 0.07 us |
| 60 messages  | 123 kB  | 216.6 us | 0.07 us |

The lazy form log.debug('form_data: %s', form_data) hands the payload to record.getMessage(), which the InterceptHandler only reaches once a record has passed the level check. With DEBUG enabled the emitted lines are byte-identical, f'{x=}' sites included: those map to %r. MistralLoader._debug_log callers get the same treatment, since that wrapper already forwards *args.
2026-07-31 19:09:01 -05:00
Timothy Jaeryang Baek bb0f898b43 refac 2026-07-31 17:41:14 -04:00
Timothy Jaeryang Baek 810378c0b8 refac 2026-07-27 19:39:36 -04:00
Timothy Jaeryang Baek 3fe03583a3 refac 2026-07-27 02:39:11 -04:00
Timothy Jaeryang Baek 80af65c24a refac 2026-07-01 03:35:46 -05:00
Timothy Jaeryang Baek 0016266c06 refac 2026-07-01 02:49:33 -05:00
Timothy Jaeryang Baek 517cd8d102 refac 2026-06-29 13:03:14 -05:00
Timothy Jaeryang Baek 2c4e1fce8f refac 2026-06-29 11:13:36 -05:00
Timothy Jaeryang Baek a285a390c1 refac 2026-06-29 06:01:05 -05:00
Timothy Jaeryang Baek 260f3c3a22 refac 2026-06-29 05:56:08 -05:00
Timothy Jaeryang Baek dbdcfd8c60 refac 2026-06-29 00:35:54 -05:00