HeinrichApfelmus / threepenny-gui

GUI framework that uses the web browser as a display.
https://heinrichapfelmus.github.io/threepenny-gui/
Other
437 stars 77 forks source link

HashMap Performance Fix #255

Closed kleinreact closed 3 years ago

kleinreact commented 3 years ago

The salt shouldn't be ignored since the HashMap has poor performance when adding new elements (as used here) otherwise. Composed types like tuples are usually hashed via chaining the elements' hashes through the salt (cf. here).

I used the following code for testing:

import qualified Graphics.UI.Threepenny as UI
import Graphics.UI.Threepenny.Core

main :: IO ()
main = startGUI defaultConfig $ \w ->
  sequence_ $ replicate 1000 $ do
    x <- string "x"
    -- insert a new element into the hashmap
    on UI.click x $ const $ return () 
    -- make the progress visible
    getBody w 
      # set style [("display","flex"), ("flex-wrap","wrap")]
      #+ [ element x ]
kleinreact commented 3 years ago

I didn't know about hashUsing before. Thus, thanks for the hint. It definitely looks like the cleaner solution.

BTW, do you see any actual performance improvements as a result of this change?

The adhoc approach and hashUsing perform quite similar, but both are a huge improvement against ignoring the salt. You can use the code snippet above for testing. The difference should be easily observable with that.

HeinrichApfelmus commented 3 years ago

Thanks a lot for the observation and fix! I have pushed a new commit 7e954264dc8356d37e0400953e486d1d80da4498 that implements Simon's suggestion.