Merge pull request #4113 from TD-er/bugfix/NoRulesReorder

[Rules] Remove "reorder rules" optimization (#4062)
This commit is contained in:
TD-er
2022-06-25 22:11:45 +02:00
committed by GitHub
11 changed files with 117 additions and 72 deletions
+1 -1
View File
@@ -227,7 +227,7 @@ Rules Settings
* Rules - Check to enable rules functionality (on next page load, extra Rules tab will appear)
* Old Engine - Default checked.
* Enable Rules Cache - Rules cache will keep track of where in the rules files each ``on ... do`` block is located. This significantly improves the time it takes to handle events. (Enabled by default, Added 2022/04/17)
* Allow Rules Event Reorder - It is best to have the rules blocks for the most frequently occuring events placed at the top of the first rules file. (also for frequently happening events, which you don't want to act on) The cached event positions can be reordered in memory based on how often an event was matched. (Enabled by default, Added 2022/04/17)
* Allow Rules Event Reorder - It is best to have the rules blocks for the most frequently occuring events placed at the top of the first rules file. (also for frequently happening events, which you don't want to act on) The cached event positions can be reordered in memory based on how often an event was matched. (Enabled by default, Added 2022/04/17, disabled 2022/06/24)
* Tolerant last parameter - When checked, the last parameter of a command will have less strict parsing.
* SendToHTTP wait for ack - When checked, the command SendToHTTP will wait for an acknowledgement from the server.
+30 -12
View File
@@ -164,8 +164,28 @@ platform_packages =
mcspr/toolchain-xtensa @ ~5.100300.211127
build_flags = ${esp82xx_3_0_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK3
lib_ignore = ${esp82xx_defaults.lib_ignore}
IRremoteESP8266
HeatpumpIR
LittleFS(esp8266)
ServoESP32
TinyWireM
[core_stage]
[core_4_0_1]
extends = esp82xx_3_0_x
platform = espressif8266@4.0.1
platform_packages =
build_flags = ${esp82xx_3_0_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK3
lib_ignore = ${esp82xx_defaults.lib_ignore}
IRremoteESP8266
HeatpumpIR
LittleFS(esp8266)
ServoESP32
TinyWireM
[core_stage_2ndheap]
extends = esp82xx_3_0_x
platform = https://github.com/platformio/platform-espressif8266.git
build_flags = ${esp82xx_3_0_x.build_flags}
@@ -173,19 +193,22 @@ build_flags = ${esp82xx_3_0_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
-DUSE_SECOND_HEAP
-DPHASE_LOCKED_WAVEFORM
platform_packages =
platformio/framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git
mcspr/toolchain-xtensa @ ~5.100300.211127
[core_stage]
extends = esp82xx_3_0_x
platform = https://github.com/platformio/platform-espressif8266.git
build_flags = ${esp82xx_3_0_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK3
-DPHASE_LOCKED_WAVEFORM
platform_packages =
platformio/framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git
mcspr/toolchain-xtensa @ ~5.100300.211127
[core_esp32_2_1_0]
platform = espressif32@2.1.0
build_flags = -DESP32_STAGE
; Updated ESP-IDF to the latest stable 4.0.1
; See: https://github.com/platformio/platform-espressif32/releases
@@ -196,11 +219,6 @@ platform = https://github.com/tasmota/platform-espressif32/re
platform_packages =
build_flags = -DESP32_STAGE
[core_esp32_3_5_0]
platform = espressif32 @ 3.5.0
platform_packages =
build_flags = -DESP32_STAGE
[core_esp32_stage]
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-idf-master
platform_packages = framework-arduinoespressif32 @ https://github.com/tasmota/arduino-esp32/releases/download/2.0.1/framework-arduinoespressif32-release_IDF4.4.tar.gz
+10 -4
View File
@@ -17,12 +17,18 @@ lib_ignore = ${core_2_7_4_alt_wifi.lib_ignore}
[core302_platform]
build_flags = ${core_3_0_2.build_flags}
platform = ${core_3_0_2.platform}
platform_packages = ${core_3_0_2.platform_packages}
lib_ignore = ${core_3_0_2.lib_ignore}
build_flags = ${core_4_0_1.build_flags}
platform = ${core_4_0_1.platform}
platform_packages = ${core_4_0_1.platform_packages}
lib_ignore = ${core_4_0_1.lib_ignore}
[beta_platform_2ndheap]
build_flags = ${core_stage_2ndheap.build_flags}
platform = ${core_stage_2ndheap.platform}
platform_packages = ${core_stage_2ndheap.platform_packages}
lib_ignore = ${core_stage_2ndheap.lib_ignore}
[beta_platform]
build_flags = ${core_stage.build_flags}
platform = ${core_stage.platform}
+48 -38
View File
@@ -70,15 +70,14 @@ extra_scripts = ${esp8266_custom_common.extra_scripts}
[env:custom_302_ESP8266_4M1M]
extends = esp8266_4M1M
platform = ${core_3_0_2.platform}
platform_packages = ${core_3_0_2.platform_packages}
build_flags = ${core_3_0_2.build_flags}
platform = ${core302_platform.platform}
platform_packages = ${core302_platform.platform_packages}
build_flags = ${core302_platform.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ${esp8266_custom_common.lib_ignore}
extra_scripts = ${esp8266_custom_common.extra_scripts}
[env:custom_beta_ESP8266_4M1M]
extends = esp8266_4M1M
platform = ${beta_platform.platform}
@@ -89,6 +88,17 @@ build_flags = ${beta_platform.build_flags}
lib_ignore = ${esp8266_custom_common.lib_ignore}
extra_scripts = ${esp8266_custom_common.extra_scripts}
[env:custom_beta_2ndheap_ESP8266_4M1M]
extends = esp8266_4M1M
platform = ${beta_platform_2ndheap.platform}
platform_packages = ${beta_platform_2ndheap.platform_packages}
build_flags = ${beta_platform_2ndheap.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ${esp8266_custom_common.lib_ignore}
extra_scripts = ${esp8266_custom_common.extra_scripts}
[env:custom_beta_IR_ESP8266_4M1M]
extends = esp8266_4M1M
platform = ${beta_platform.platform}
@@ -110,21 +120,21 @@ lib_ignore = ESP32_ping
extra_scripts = ${esp8266_custom_common.extra_scripts}
[env:custom_beta_debug_ESP8266_4M1M]
extends = esp8266_4M1M
platform = ${beta_platform.platform}
platform_packages = ${beta_platform.platform_packages}
build_flags = ${beta_platform.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
-g
-DDEBUG_ESP_OOM
-DUMM_POISON_CHECK
-DDEBUG_ESP_PORT=Serial
build_unflags =
lib_ignore = ${esp8266_custom_common.lib_ignore}
extra_scripts = ${esp8266_custom_common.extra_scripts}
; TD-er: Disabled as it will no longer fit
;[env:custom_beta_debug_ESP8266_4M1M]
;extends = esp8266_4M1M
;platform = ${beta_platform.platform}
;platform_packages = ${beta_platform.platform_packages}
;build_flags = ${beta_platform.build_flags}
; ${esp8266_4M1M.build_flags}
; -DPLUGIN_BUILD_CUSTOM
; -g
; -DDEBUG_ESP_OOM
; -DUMM_POISON_CHECK
; -DDEBUG_ESP_PORT=Serial
;build_unflags =
;lib_ignore = ${esp8266_custom_common.lib_ignore}
;extra_scripts = ${esp8266_custom_common.extra_scripts}
; Custom: 4M2M version -- SPIFFS --------------
@@ -230,9 +240,9 @@ lib_ignore = ${regular_platform_alt_wifi.lib_ignore}
;[env:normal_302_ESP8266_1M]
;extends = esp8266_1M
;platform = ${core_3_0_2.platform}
;platform_packages = ${core_3_0_2.platform_packages}
;build_flags = ${core_3_0_2.build_flags}
;platform = ${core302_platform.platform}
;platform_packages = ${core302_platform.platform_packages}
;build_flags = ${core302_platform.build_flags}
; ${esp8266_1M.build_flags}
@@ -321,11 +331,11 @@ lib_ignore = ${regular_platform_alt_wifi.lib_ignore}
[env:normal_302_ESP8266_4M1M]
extends = esp8266_4M1M
platform = ${core_3_0_2.platform}
platform_packages = ${core_3_0_2.platform_packages}
build_flags = ${core_3_0_2.build_flags}
platform = ${core302_platform.platform}
platform_packages = ${core302_platform.platform_packages}
build_flags = ${core302_platform.build_flags}
${esp8266_4M1M.build_flags}
lib_ignore = ${core_3_0_2.lib_ignore}
lib_ignore = ${core302_platform.lib_ignore}
SD
SDFS
LittleFS(esp8266)
@@ -391,17 +401,17 @@ build_flags = ${regular_platform.build_flags}
[env:minimal_core_302_ESP8266_1M_OTA_Domoticz]
extends = esp8266_1M_OTA
platform = ${core_3_0_2.platform}
platform_packages = ${core_3_0_2.platform_packages}
build_flags = ${core_3_0_2.build_flags}
platform = ${core302_platform.platform}
platform_packages = ${core302_platform.platform_packages}
build_flags = ${core302_platform.build_flags}
${esp8266_1M_OTA.build_flags}
${minimal_OTA_domoticz.build_flags}
[env:minimal_core_302_ESP8285_1M_OTA_Domoticz]
extends = esp8285_1M_OTA
platform = ${core_3_0_2.platform}
platform_packages = ${core_3_0_2.platform_packages}
build_flags = ${core_3_0_2.build_flags}
platform = ${core302_platform.platform}
platform_packages = ${core302_platform.platform_packages}
build_flags = ${core302_platform.build_flags}
${esp8285_1M_OTA.build_flags}
${minimal_OTA_domoticz.build_flags}
@@ -424,17 +434,17 @@ build_flags = ${regular_platform.build_flags}
[env:minimal_core_302_ESP8266_1M_OTA_FHEM_HA]
extends = esp8266_1M_OTA
platform = ${core_3_0_2.platform}
platform_packages = ${core_3_0_2.platform_packages}
build_flags = ${core_3_0_2.build_flags}
platform = ${core302_platform.platform}
platform_packages = ${core302_platform.platform_packages}
build_flags = ${core302_platform.build_flags}
${esp8266_1M_OTA.build_flags}
${minimal_OTA_FHEM_HA.build_flags}
[env:minimal_core_302_ESP8285_1M_OTA_FHEM_HA]
extends = esp8285_1M_OTA
platform = ${core_3_0_2.platform}
platform_packages = ${core_3_0_2.platform_packages}
build_flags = ${core_3_0_2.build_flags}
platform = ${core302_platform.platform}
platform_packages = ${core302_platform.platform_packages}
build_flags = ${core302_platform.build_flags}
${esp8285_1M_OTA.build_flags}
${minimal_OTA_FHEM_HA.build_flags}
+6 -5
View File
@@ -782,7 +782,7 @@ bool mcpgpio_range_pattern_helper(struct EventStruct *event, const char *Line, b
uint8_t readValue;
const uint8_t currentVal = data.initVal + i;
const uint8_t currentAddress = static_cast<int>(currentVal / 2);
const uint8_t currentMask = (data.mask >> (8 * i)) & 0xFF;
uint8_t currentMask = (data.mask >> (8 * i)) & 0xFF;
const uint8_t currentInvertedMask = 0xFF - currentMask;
const uint8_t currentWrite = (data.write >> (8 * i)) & 0xFF;
const uint8_t currentGPIORegister = ((currentVal % 2) == 0) ? MCP23017_GPIOA : MCP23017_GPIOB;
@@ -805,9 +805,8 @@ bool mcpgpio_range_pattern_helper(struct EventStruct *event, const char *Line, b
}
const uint8_t mode = (onLine) ? PIN_MODE_OUTPUT : PIN_MODE_OFFLINE;
for (uint8_t j = 0; j < 8; j++) {
// if ((currentMask & (uint8_t(pow(2,j)))) >> j) { //only for the pins in the mask
if ((currentMask & (1 << j)) >> j) { // only for the pins in the mask
for (uint8_t j = 0; currentMask != 0 && j < 8; j++) {
if (currentMask & 1) { // only for the pins in the mask
uint8_t currentPin = data.firstPin + j + 8 * i;
const uint32_t key = createKey(PLUGIN_MCP, currentPin);
@@ -823,6 +822,7 @@ bool mcpgpio_range_pattern_helper(struct EventStruct *event, const char *Line, b
addLog(LOG_LEVEL_INFO, log);
SendStatusOnlyIfNeeded(event, SEARCH_PIN_STATE, key, log, 0);
}
currentMask >>= 1; // Shift the mask 1 position
}
}
return onLine;
@@ -867,7 +867,7 @@ bool pcfgpio_range_pattern_helper(struct EventStruct *event, const char *Line, b
uint8_t currentPin = data.firstPin + j + 8 * i;
const uint32_t key = createKey(PLUGIN_PCF, currentPin);
if ((currentMask & (1 << j)) >> j) { // only for the pins in the mask
if (currentMask & 1) { // only for the pins in the mask
state = onLine ? ((writeGPIOValue & (1 << j)) >> j) : -1;
createAndSetPortStatus_Mode_State(key, mode, state);
@@ -882,6 +882,7 @@ bool pcfgpio_range_pattern_helper(struct EventStruct *event, const char *Line, b
readValue |= (1 << j); // set port j = 1
}
}
currentMask >>= 1; // Shift the mask 1 position
}
if (onLine) {
+11 -2
View File
@@ -29,7 +29,13 @@ bool RulesEventCache::addLine(const String& line, const String& filename, size_t
RulesEventCache_vector::const_iterator RulesEventCache::findMatchingRule(const String& event, bool optimize)
{
RulesEventCache_vector::iterator it = _eventCache.begin();
RulesEventCache_vector::iterator prev = _eventCache.end();
// RulesEventCache_vector::iterator prev = _eventCache.end();
// FIXME TD-er: Disable optimize as it has some side effects.
// For example, matching a specific event first and then a more generic one is perfectly normal to do.
// But this optimization will then put the generic one in front as it will be matched more often.
// Thus it will never match the more specific one anymore.
for (; it != _eventCache.end(); ++it)
{
@@ -38,6 +44,7 @@ RulesEventCache_vector::const_iterator RulesEventCache::findMatchingRule(const S
STOP_TIMER(RULES_MATCH);
if (match) {
/*
if (optimize) {
it->_nrTimesMatched++;
@@ -50,9 +57,10 @@ RulesEventCache_vector::const_iterator RulesEventCache::findMatchingRule(const S
}
}
}
*/
return it;
}
/*
if (optimize) {
if (prev == _eventCache.end()) {
prev = it;
@@ -62,6 +70,7 @@ RulesEventCache_vector::const_iterator RulesEventCache::findMatchingRule(const S
prev = it;
}
}
*/
}
return it;
}
+5 -4
View File
@@ -96,12 +96,12 @@ void sw_watchdog_callback(void *arg)
\*********************************************************************************************/
void ESPEasy_setup()
{
#ifdef ESP8266_DISABLE_EXTRA4K
#if defined(ESP8266_DISABLE_EXTRA4K) || defined(USE_SECOND_HEAP)
disable_extra4k_at_link_time();
#endif // ifdef ESP8266_DISABLE_EXTRA4K
#endif
#ifdef PHASE_LOCKED_WAVEFORM
enablePhaseLockedWaveform();
#endif // ifdef PHASE_LOCKED_WAVEFORM
#endif
#ifdef USE_SECOND_HEAP
HeapSelectDram ephemeral;
#endif
@@ -126,11 +126,12 @@ void ESPEasy_setup()
}
}
#endif // CONFIG_IDF_TARGET_ESP32
#endif // ESP32
#ifndef BUILD_NO_RAM_TRACKER
lowestFreeStack = getFreeStackWatermark();
lowestRAM = FreeMem();
#endif // ifndef BUILD_NO_RAM_TRACKER
#endif // ESP32
initWiFi();
run_compiletime_checks();
+2 -2
View File
@@ -94,7 +94,7 @@ const __FlashStringHelper * getLabel(LabelType::Enum label) {
case LabelType::JSON_BOOL_QUOTES: return F("JSON bool output without quotes");
case LabelType::ENABLE_TIMING_STATISTICS: return F("Collect Timing Statistics");
case LabelType::ENABLE_RULES_CACHING: return F("Enable Rules Cache");
case LabelType::ENABLE_RULES_EVENT_REORDER: return F("Optimize Rules Cache Event Order");
// case LabelType::ENABLE_RULES_EVENT_REORDER: return F("Optimize Rules Cache Event Order"); // TD-er: Disabled for now
case LabelType::TASKVALUESET_ALL_PLUGINS: return F("Allow TaskValueSet on all plugins");
case LabelType::ALLOW_OTA_UNLIMITED: return F("Allow OTA without size-check");
case LabelType::ENABLE_CLEAR_HUNG_I2C_BUS: return F("Try clear I2C bus when stuck");
@@ -291,7 +291,7 @@ String getValue(LabelType::Enum label) {
case LabelType::JSON_BOOL_QUOTES: return jsonBool(Settings.JSONBoolWithoutQuotes());
case LabelType::ENABLE_TIMING_STATISTICS: return jsonBool(Settings.EnableTimingStats());
case LabelType::ENABLE_RULES_CACHING: return jsonBool(Settings.EnableRulesCaching());
case LabelType::ENABLE_RULES_EVENT_REORDER: return jsonBool(Settings.EnableRulesEventReorder());
// case LabelType::ENABLE_RULES_EVENT_REORDER: return jsonBool(Settings.EnableRulesEventReorder()); // TD-er: Disabled for now
case LabelType::TASKVALUESET_ALL_PLUGINS: return jsonBool(Settings.AllowTaskValueSetAllPlugins());
case LabelType::ALLOW_OTA_UNLIMITED: return jsonBool(Settings.AllowOTAUnlimited());
case LabelType::ENABLE_CLEAR_HUNG_I2C_BUS: return jsonBool(Settings.EnableClearHangingI2Cbus());
+1 -1
View File
@@ -62,7 +62,7 @@ struct LabelType {
JSON_BOOL_QUOTES,
ENABLE_TIMING_STATISTICS,
ENABLE_RULES_CACHING,
ENABLE_RULES_EVENT_REORDER,
// ENABLE_RULES_EVENT_REORDER, // TD-er: Disabled for now
TASKVALUESET_ALL_PLUGINS,
ALLOW_OTA_UNLIMITED,
ENABLE_CLEAR_HUNG_I2C_BUS,
+2 -2
View File
@@ -116,7 +116,7 @@ void handle_advanced() {
#endif
Settings.EnableRulesCaching(isFormItemChecked(LabelType::ENABLE_RULES_CACHING));
Settings.EnableRulesEventReorder(isFormItemChecked(LabelType::ENABLE_RULES_EVENT_REORDER));
// Settings.EnableRulesEventReorder(isFormItemChecked(LabelType::ENABLE_RULES_EVENT_REORDER)); // TD-er: Disabled for now
Settings.AllowOTAUnlimited(isFormItemChecked(LabelType::ALLOW_OTA_UNLIMITED));
@@ -139,7 +139,7 @@ void handle_advanced() {
addFormCheckBox(F("Old Engine"), F("oldrulesengine"), Settings.OldRulesEngine());
#endif // WEBSERVER_NEW_RULES
addFormCheckBox(LabelType::ENABLE_RULES_CACHING, Settings.EnableRulesCaching());
addFormCheckBox(LabelType::ENABLE_RULES_EVENT_REORDER, Settings.EnableRulesEventReorder());
// addFormCheckBox(LabelType::ENABLE_RULES_EVENT_REORDER, Settings.EnableRulesEventReorder()); // TD-er: Disabled for now
addFormCheckBox(F("Tolerant last parameter"), F("tolerantargparse"), Settings.TolerantLastArgParse());
addFormNote(F("Perform less strict parsing on last argument of some commands (e.g. publish and sendToHttp)"));
+1 -1
View File
@@ -289,7 +289,7 @@ set -o pipefail; pip install -r ${SRC}/requirements.txt | { grep -v "already sat
# Update (and clean) all targets
# N.B. clean does also install missing packages which must be installed before applying patches.
platformio update
platformio pkg update
platformio run --target clean
# patch platformio core libs for PUYA bug (https://github.com/letscontrolit/ESPEasy/issues/650)
cd ${SRC}/patches; ./check_puya_patch;