Tuning LWIP HTTP Server (httpd) on Raspberry Pi Pico W

I have extended the LWIP HTTP server to make a WiFi web server that serves files from SD cards on Raspberry Pi Pico W using architecture pico_cyw43_arch_lwip_sys_freertos [1]. It works, but it is slow for large files. For example, I have a web page that embeds an 85 kB jpg image, and it sometimes takes almost 40 seconds to load according to Chrome Developer Tools. However, the speed varies considerably. Sometimes it only takes 5 or 6 seconds or so to load. So, I’m pretty sure the hardware is capable of much better performance, but something is holding it back.

I started with lwipopts.h copied from pico-examples/pico_w/wifi/lwipopts_examples_common.h. I tried adjusting some of the parameters, e.g.:

TCP_SND_BUF (8 * TCP_MSS) to (16 * TCP_MSS)

and that seemed to help, but I am just stabbing in the dark here. I’m not very familiar with LWIP. Do you have any suggestions?

[1] Architecture for integrating the CYW43 driver (for the wireless on Pico W) and lwIP (for TCP/IP stack) into the SDK. pico_cyw43_arch_lwip_sys_freertos - For using the full lwIP API including blocking sockets in OS (NO_SYS=0 ) mode, along with with multi-core/task/thread safety, and automatic servicing of the cyw43_driver and the lwIP stack. See Raspberry Pi Documentation, Networking Libraries.

This question seems related to LWIP and you are likely to get better response on their forums.