Skip to content

TTFX time of request is high. MVP #1194

@Sixzero

Description

@Sixzero

I would think this should run in 0.1seconds even on first call (not 6 seconds), because it is one of the most common way we construct a POST request.

(method, url, serialized_body) = (:POST, "http://localhost:9000", "{\"content\":\"Hello\"}", )
@time HTTP.request(method, url; body=serialized_body)
@time HTTP.request(method, url; body=serialized_body);
  5.951766 seconds (7.45 M allocations: 502.251 MiB, 2.99% gc time, 115.65% compilation time)
  0.000566 seconds (153 allocations: 144.898 KiB)

An example server for testing:

using HTTP
using JSON3

function handle_request(req::HTTP.Request)
    try
        body = JSON3.read(String(req.body))
        response = Dict("content" => body.contents)
        return HTTP.Response(200, ["Content-Type" => "application/json"], 
                           JSON3.write(response))
    catch e
        return HTTP.Response(200, ["Content-Type" => "application/json"],
                           JSON3.write(Dict("error" => string(e))))
    end
end

HTTP.serve("0.0.0.0", 9000) do req
    handle_request(req)
end

What is going on ? Am I missing something? I see so many packages using this very same line, and literally everywhere these long compilations are happening!

<!--
Please specify the following versions when submitting a bug report:
 - Julia 1.10.6
 - HTTP.jl v1.10.8
 - MbedTLS.jl  not installed?
-->

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