Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkSProxies generates a LOT of boilerplate code #75

Closed
dariooddenino opened this issue Jun 9, 2021 · 5 comments
Closed

mkSProxies generates a LOT of boilerplate code #75

dariooddenino opened this issue Jun 9, 2021 · 5 comments

Comments

@dariooddenino
Copy link

Environment

  • purescript-halogen 6.1.0
  • purescript-halogen-formless 2.0.1

Hi!
While doing some profiling for one of my purescript webapps, I found out that one single formless component was generating a 180kb js file on its own. A ~300LOC ps component was generating almost 3k LOC of javascript code.

I found out that the main culprit was mkSProxies. Every time one of the proxies is used, a huge block of code is generated.
For example by just using prx.maxUsages the js code would result in:

new Data_Symbol.IsSymbol(function () {
            return "maxUsages";
        }))()()((Components_Coupon_Types.prx()()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "active";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "code";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "description";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "individualUse";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "isAuto";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "maxUsages";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "minAmount";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "minQty";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "platforms";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "productsIn";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "productsOut";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "regionsIn";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "regionsOut";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "travelFrom";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "travelTo";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "type";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "typesIn";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "typesOut";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "validFrom";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "validTo";
        }))()(Formless_Transform_Row.makeSProxiesCons(new Data_Symbol.IsSymbol(function () {
            return "value";
        }))()(Formless_Transform_Row.makeSProxiesNil))))))))))))))))))))))).maxUsages

By replacing mkSproxies with a manually written record of proxies the file size went down from ~180K to ~90K.

Similar things happen in other places (for example when defining render, handleAction and handleEvent) but I guess that's a consequence of how this library was designed and are probably not as easily solvable as this one.

For now I'm replacing all of mkSproxies usages, but I was wondering if I'm doing anything wrong on my end.

Thanks!

@JordanMartinez
Copy link

JordanMartinez commented Jun 9, 2021 via email

@dariooddenino
Copy link
Author

I thought that maybe this one flew under the radar. It's not a big deal, maybe just worth explaining this in the docs since the impact of using it is so big

@thomashoneyman
Copy link
Owner

thomashoneyman commented Oct 6, 2021

Sorry for such a late response -- I'm probably going to remove this function altogether because it really is terrible. At the time I wrote it (while learning PureScript) I didn't understand the ridiculous code bloat that came along with it, and just enjoyed the reduced boilerplate, but it's really not worth it and I wouldn't advise anyone use it outside of a toy situation.

@thomashoneyman
Copy link
Owner

@dariooddenino What do you think of #77?

@dariooddenino
Copy link
Author

@thomashoneyman I think that it's a good solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants