Skip to content

Performance-killing bug in sockets.cpp #60

@SapientHetero

Description

@SapientHetero

socketSend() writes the data to be transmitted to one of the W5x00's circular socket buffers, then waits for the data to be sent before returning. Waiting is unnecessary because the next socketSend() call checks for available space in the socket's circular buffer before sending more data, and it eliminates the advantage of the W5x00 being able to send the data without interacting with the processor.

Removing the wait by deleting the following lines increases W5500 transmit throughput by a whopping 4X on my Adafruit Metro M4/W5500 Shield webserver with no impact on reliability. I don't have W5100 or W5200 devices to test with but based on documentation review I see no reason this improvement won't work on them too.

/* +2008.01 bj */
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK ) {
	/* m2008.01 [bj] : reduce code */
	if ( W5100.readSnSR(s) == SnSR::CLOSED ) {
		EthernetClass::spi()->endTransaction();
		return 0;
	}
	EthernetClass::spi()->endTransaction();
	yield();
	EthernetClass::spi()->beginTransaction(SPI_ETHERNET_SETTINGS);
}
/* +2008.01 bj */
W5100.writeSnIR(s, SnIR::SEND_OK);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions