rtfeldman / elm-spa-example

A Single Page Application written in Elm
https://dev.to/rtfeldman/tour-of-an-open-source-elm-spa
MIT License
3.29k stars 531 forks source link

The app builds too long, in case of a lot of messages to handle in the Update function #28

Closed YevheniyGloba closed 6 years ago

YevheniyGloba commented 7 years ago

Hello. I have a question regarding handling a lot of messages in the Main file for update section: type Msg = SetRoute (Maybe Route) | HomeLoaded (Result PageLoadError Home.Model) ...

Imagine that you have a lot of these messages (in our example we have 32 messages, and 31 of them are like HomeLoaded (Result PageLoadError Home.Model) .. and HomeMsg Home.Msg) And here we have a problem with building our app - it takes up to 50 seconds to build app.

Could you help us? Could you give us some help?

mbomhoff commented 7 years ago

We are seeing the same issue with long build times, however our code has 67 messages and takes about 10 minutes to build. Please see https://github.com/hurwitzlab/elm-imicrobe-spa

mbomhoff commented 7 years ago

Apparently this is a known issue with tuple pattern matching in elm 0.18: https://groups.google.com/d/topic/elm-dev/QGmwWH6V8-c/discussion

I followed the suggestion in the thread of breaking the tuple matching into nested cases and my build time decreased to 3-4 seconds.

For example, instead of case (msg, page) of use case msg of and redundantly handle the _ page cases where needed.

YevheniyGloba commented 7 years ago

@mbomhoff, thanks. we have changed message handlers to reduce the number of possible variants in the case statement, and it works

rtfeldman commented 6 years ago

Can this be closed? Seems like it has been worked out. 😄

YevheniyGloba commented 6 years ago

@rtfeldman yes, it could be closed