maximkulkin / esp-homekit

Apple HomeKit accessory server library for ESP-OPEN-RTOS
MIT License
1.11k stars 170 forks source link

Finding a (better) balance between speed and memory usage #6

Closed HomeACcessoryKid closed 6 years ago

HomeACcessoryKid commented 6 years ago

I have done some profiling and noticed that you did not use the same concept as I did with respect to the curve25519 code. In the current code you require a whopping 6 seconds to do the pair-verify procedure. Unlike pairing, this procedure is mission critical since it is executed often while using the Accessory. Using my approach bottom and not using ED25519_SMALL the speed of the crypto goes up by a factor of 20! bringing a new connection (and offering service to the user) back to 1 second. It will require a bigger task and this brings me to the next improvement needed.

The current task structure is set on an initial task of 1700 stack which continues to do mdns and spawning additional tasks for each connected client at 768 bytes.

This should be changed such that only two tasks remain, a small one for mdns and a big one for all the clients together. I have not gone deeper in this area to prevent my spaghetti coding skill in a pull request, but we can discuss the strategy. It is the one I applied in my repository.

maximkulkin commented 6 years ago

Fixed: now server uses poll to handle all clients in a single task and thus memory is not consumed that much, was able to remove ED25519_SMALL which increased performance. Now pair verify takes only ~1sec which AFAU is acceptable.