Skip to content

Slow performance caused by get_remote_ip_and_port and get_local_ip_and_port #1923

@yhirose

Description

@yhirose

Currently, one of bottle necks of performance is caused by get_remote_ip_and_port and get_local_ip_and_port.

image

cpp-httplib/httplib.h

Lines 6961 to 6967 in 61c4180

strm.get_remote_ip_and_port(req.remote_addr, req.remote_port);
req.set_header("REMOTE_ADDR", req.remote_addr);
req.set_header("REMOTE_PORT", std::to_string(req.remote_port));
strm.get_local_ip_and_port(req.local_addr, req.local_port);
req.set_header("LOCAL_ADDR", req.local_addr);
req.set_header("LOCAL_PORT", std::to_string(req.local_port));

These slow functions are called regardless of whether REMOTE_ADDR, REMOTE_PORT, LOCAL_ADDR, or LOCAL_PORT will be used later on.

I am thinking of making them "lazy evaluation" calls, so that we don't have to pay such costs.

  • REMOTE_ADDR, REMOTE_PORT, LOCAL_ADDR, LOCAL_PORT will be removed from Request
  • remote_addr, remote_port, local_addr, local_port will be removed from Request
  • get_remote_ip, get_remote_port, get_local_ip and get_local_port will be added

This will be a break change, and will be available from v0.18.0.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions