Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve optimistic_yield intervals for performance gain in sketches #7952

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dok-net
Copy link
Contributor

@dok-net dok-net commented Mar 31, 2021

The purpose of optimistic_yield is to be used in library functions that get called in tight loops from CONT, in order to avoid unnecessarily frequent yields to SYS, and the performance impact that entails. This PR tries to identify and fix a few places where very low intervals were used for no obvious purpose.

@dok-net dok-net mentioned this pull request Mar 31, 2021
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 2 times, most recently from 58708b3 to 8b164cc Compare April 9, 2021 22:34
Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, I think the existing constants in optimistic_yield were chosen as a best-guess with no real "100% correct answer" possible. So I looked at the reasoning as to why the oy was there in the 1st place and how the change would affect it (considering expectation value of wait times for busywait loops).

cores/esp8266/flash_hal.cpp Outdated Show resolved Hide resolved
cores/esp8266/flash_hal.cpp Outdated Show resolved Hide resolved
cores/esp8266/uart.cpp Show resolved Hide resolved
libraries/ESP8266WiFi/src/WiFiClient.cpp Outdated Show resolved Hide resolved
libraries/ESP8266WiFi/src/WiFiUdp.cpp Outdated Show resolved Hide resolved
libraries/Wire/Wire.cpp Outdated Show resolved Hide resolved
cores/esp8266/core_esp8266_i2s.cpp Outdated Show resolved Hide resolved
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 2 times, most recently from afb2656 to 40cff9e Compare April 11, 2021 21:46
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 7 times, most recently from b903aa6 to b8bd44b Compare May 18, 2021 13:40
libraries/ESP8266WiFi/src/WiFiUdp.cpp Show resolved Hide resolved
cores/esp8266/uart.cpp Show resolved Hide resolved
const uint32_t pulse_start_cycle_count = xthal_get_ccount();
WAIT_FOR_PIN_STATE(!state);
if (!waitForPinState(pin, !state, timeout_cycles, start_cycle_count)) {
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong per my reading of the (not so hot docs) https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/?setlang=it

Return 0 on no pulse beginning edge detected. OTW, it should return the full timeout as the pulse width (i.e. get rid of the return 0 and just fallthru tho the return below).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@earlephilhower I thought I had answered a long time before. IIRC I researched and besides this refactoring not changing how the return works before, my reading of the docs etc was that returning 0 was and is correct. Hm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@earlephilhower Can you agree this year; the change is just same effective execution path as with the macros before?

@dok-net dok-net force-pushed the optimistic_yield_intervals branch from b8bd44b to da6c4e8 Compare May 23, 2021 17:09
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 3 times, most recently from c2b436e to 7fe3607 Compare June 8, 2021 01:42
@dok-net dok-net force-pushed the optimistic_yield_intervals branch from 7fe3607 to e58126f Compare June 28, 2021 10:43
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 2 times, most recently from dc76df9 to e80a82b Compare October 16, 2021 10:36
@dok-net dok-net force-pushed the optimistic_yield_intervals branch 2 times, most recently from fbaebe3 to bd32d2c Compare March 13, 2022 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants