reflex
reflex copied to clipboard
traceDynWith seems to fire more often than expected
It was my understanding that traceDynWith
should fire at most one time for each time the traced Dynamic was updated. In my program I am observing that it fires many times for the same Dynamic when the Dynamic has not been updated.
How did I observe this? The Dynamic is constructed using scanDynMaybe
and I added an integer counter field to count how many times scanDynMaybe
was updating itself.
Then in traceDynWith
, I printed out this number whenever traceDynWith
fired. In this log snippet, you can see that the trace fires twice despite the number not incrementing at all.
D:NormalizedFilePath "compiler/GHC/Driver/Backpack.hs": GetHiFile:((2)Just "vES\247\217\199E\135",(V:GHC.Driver.Backpack))
D:NormalizedFilePath "compiler/GHC/Driver/Backpack.hs": GetHiFile:((2)Just "vES\247\217\199E\135",(V:GHC.Driver.Backpack))
Perhaps this is not a bug but it confused me for at least an hour.
It's possible for a Dynamic to be updated to the same value that it already had, and traceDynWith will still print its message when that occurs. You should be able to use holdUniqDyn on the Dynamic first if you want to remove such duplicate updates.
@cgibbard I have built an abstraction which should prevent these kinds of updates and which reports a different number of updates to the number of times traceDynWith
fires.
https://github.com/mpickering/ghcide/blob/reflex/src/Development/IDE/Core/Reflex/Early.hs