Skip to content

Performance Improvement for ESP8266 code#1530

Merged
revoxhere merged 2 commits intoduino-coin:masterfrom
snakeye:master
Aug 5, 2022
Merged

Performance Improvement for ESP8266 code#1530
revoxhere merged 2 commits intoduino-coin:masterfrom
snakeye:master

Conversation

@snakeye
Copy link
Contributor

@snakeye snakeye commented Jul 8, 2022

Performance improvement of the difficulty loop

  • Moved conversion outside of the loop
  • Using fast memory comparison

Tested on ESP-12e board, the hash rate improved from ~10KH/s to ~30KH/s

@revoxhere
Copy link
Member

Nice job! Have you tested it also on other boards? I'll need to update Kolka to make it run correctly 😅

@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

I do have only ESP01 here but the firmware does not fit the flash. Need to disable ArduinoOTA and WebServer first.

@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

By the way, using the {fmt} library allows achieving ~40KH/s on this board. Let me make another PR...

@revoxhere
Copy link
Member

While you're on it, could you check if maybe similar thing isn't happening in the ESP32 code? I believe it could go even faster if 8266 is capable of doing these numbers now.

@revoxhere revoxhere self-assigned this Jul 8, 2022
@revoxhere revoxhere added enhancement New feature or request in progress This is currently being worked on labels Jul 8, 2022
@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

Surely will check ESP32 next.

@snakeye snakeye changed the title Elimitated byte array to string conversion in the loop Performance Improvement for ESP8266 code Jul 8, 2022
@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

Added another commit with {fmt}. It will require https://github.com/fmtlib/fmt as a dependency

@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

The ESP32 code seems to use hash conversion outside of the loop and memcmp already.

@GerardoNevarez
Copy link
Contributor

The ESP32 code seems to use hash conversion outside of the loop and memcmp already.

What about using fmt on the esp32?

@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

It clearly makes sense :)

@LDarki
Copy link
Collaborator

LDarki commented Jul 8, 2022

You missed { in this part of the code:
image

Also, I tested the code on my Nodemcu esp8266 v2 (Amida)
And my hashrate changed from ~10KH/s to ~9.7KH/s

Edit: sometimes it changes from 10KH/s to 30KH/s but something is weird here lol.

@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

Right, fixed the missing bracket.

@GerardoNevarez
Copy link
Contributor

Almost all the users use the Arduino IDE, if you can't provide a easy, IDE native way to add the fmt library, maybe is best to remove it...

@revoxhere
Copy link
Member

Indeed, the fmt may be a bit too much, but the rest looks like it can be added for the future version.

@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

Good point. I'm not using Arduino IDE at all. How do people add the dependencies there, ArduinoJSON for example?

@GerardoNevarez
Copy link
Contributor

Tools > Manage Libraries > search.

There is a centralized directory of Arduino IDE ready libraries, another option is making the library code available on the libraries folder.. i.e. for me, on Windows, is on Documents\Arduino\libraries

Look at this, for an example of a library that can be dropped into that folder: https://github.com/me-no-dev/ESPAsyncWebServer

See the library.json and library.properties files

@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

On PlatformIO I just add the dependency in the .ini file - https://registry.platformio.org/libraries/fmtlib/fmt/installation and it is stored in a code. Arduino IDE creates to much hassle :( Okay, I'm fine to remove fmt then.

@GerardoNevarez
Copy link
Contributor

I get an average of 25.38 kH/s, with peaks of 29.51kH/s. And OTA, webserver works on ESP-01S (1 meg of flash)

Kolka is not happy 😁 (ignore the share number, had a few unrelated restarts)

...
BAD,Incorrect difficulty share #3 (2991) hashrate: 29.14 kH/s (0.10s)
...
BAD,Incorrect difficulty share #4 (33667) hashrate: 26.85 kH/s (1.25s)
...
BAD,Incorrect difficulty share #1 (66999) hashrate: 23.78 kH/s (2.82s)
BAD,Incorrect difficulty share #2 (37063) hashrate: 26.38 kH/s (1.41s)
...

the difficulty change is very random... might revert back to 3.18 code to avoid getting flagged

@snakeye
Copy link
Contributor Author

snakeye commented Jul 8, 2022

I've just tested with ESP-01 (512K flash) and fmt, the results are quite the same as ESP-12e:

BAD,Incorrect difficulty share #1 (5061) hashrate: 42.33 kH/s (0.12s)
BAD,Incorrect difficulty share #2 (89078) hashrate: 40.86 kH/s (2.18s)
GOOD share #3 (3300134) hashrate: 38.35 kH/s (86.04s)
GOOD share #4 (67040) hashrate: 41.03 kH/s (1.63s)
GOOD share #5 (374274) hashrate: 39.98 kH/s (9.36s)
GOOD share #6 (337099) hashrate: 40.02 kH/s (8.42s)
GOOD share #7 (391612) hashrate: 39.96 kH/s (9.80s)

Could it be that PlatformIO gives some better optimizations over Arduino IDE?

@GerardoNevarez
Copy link
Contributor

GerardoNevarez commented Jul 8, 2022

could be, likely has an updated gcc, but even details as the version of the nonos-sdk version ( 2.2.1+119 ), and/or using a higher bandwidth version of the LwIP stack can affect things... for me sometimes can be the difference between a 8.5kH/s and a 10.1 kH/s average on the regular code.

@GerardoNevarez
Copy link
Contributor

Maybe there's an easier way to add {fmt}, if you have that code in a different branch in your repo, I can try this:

To use the {fmt} library, add fmt/core.h, fmt/format.h, fmt/format-inl.h, src/format.cc and optionally other headers from a release archive or the Git repository to your project.

@revoxhere revoxhere merged commit a676bdd into duino-coin:master Aug 5, 2022
@ardibnft
Copy link

ardibnft commented Aug 7, 2022

I am using ESP8266, and I just flashed them, loaded the code in Arduino, and it worked immediately, maybe the error was corrected by the time I downloaded the code. I get between 35KH - 37KH.

You missed { in this part of the code: image

Also, I tested the code on my Nodemcu esp8266 v2 (Amida) And my hashrate changed from ~10KH/s to ~9.7KH/s

Edit: sometimes it changes from 10KH/s to 30KH/s but something is weird here lol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request in progress This is currently being worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants