esp-rs / esp-flasher-stub

Rust implementation of flasher stub located in esptool
Apache License 2.0
18 stars 10 forks source link

Remove/Limit usage of `dyn` #22

Closed MabezDev closed 11 months ago

MabezDev commented 1 year ago

Using dyn should be avoided, as it will inflate the binary size due to the addition of the vtable. The addition of the vtable may also affect the cache performance as the vtable might end up being a jump to somewhere far away from the currently executing code. Instead of dyn we should use an enum and implement the InputIO on that. Depending on the enum variant I.e Transport::Uart or Transport::Usb selected, the behaviour will be different at run time.

igrr commented 1 year ago

The addition of the vtable may also affect the cache performance as the vtable might end up being a jump to somewhere far away from the currently executing code.

Note that while this is true in general, in the specific case of esp-flasher-stub this doesn't matter since all the code is in the internal RAM. On existing ESP chips, internal RAM is accessed directly without caching (TCM).