Query inside Dynamic triggers continuous high CPU load for FE
A quick fix is to add TrackedSymbols :> {searchstring}
to the Dynamic
.
But at the end it is just another example from a neverending series "Dynamic does/not fire unexpectedly".
This series taught me to not use Dynamic
to calculate things but only to display them. It will be more work on your side but it will dramatically reduce number of headaches.
This is how more or less I do things lately:
DynamicModule[
{searchstring, viewResults, searchstringSet}
, {
InputField[Dynamic[searchstring,searchstringSet[#]&], String, ContinuousAction->True]
, Dynamic[viewResults]
}
, Initialization:>(
searchstringSet[val_]:=(
searchstring=val
; viewResults = {<|"aa"->1,"bb"->1|>,<|"aa"->2,"bb"->2|>} // Query[Select[#"aa"<2.*StringLength@searchstring&]]
)
; searchstringSet["tr"]
)
]
You may use the TrackedSymbols
option on either DynamicModule
or Dynamic
.
From the comments in the OP the front-end cannot determine when to refresh the dynamic with the usage of the dynamic variable in Query
. You can explicitly tell the front-end which variable to track for updates with TrackedSymbols
.
DynamicModule[{searchstring = "tr"},
Dynamic[
{<|"aa" -> 1, "bb" -> 1|>, <|"aa" -> 2, "bb" -> 2|>} //
Query[Select[#"aa" < 2.*StringLength@searchstring &]],
TrackedSymbols :> {searchstring}]
]
Now that the symbols to track have been explicitly provided, the front-end will only refresh the Dynamic
when that symbol changes.
Hope this helps.