These are chat archives for opal/opal

3rd
Aug 2016
Mitch VanDuyn
@catmando
Aug 03 2016 18:11
hey folks, how can I turn off opal source mapping in rails... its soooo slow (or something is) in opal > 0.8
Jamie Gaskins
@jgaskins
Aug 03 2016 18:29
@catmando Opal::Config.source_map_enabled = false. Alternatively, you could just set config.assets.debug = false in your config/development.rb, which will concatenate assets and turn off source maps.
Mitch VanDuyn
@catmando
Aug 03 2016 18:29
thanks!
do we understand why it got so slow?
Jamie Gaskins
@jgaskins
Aug 03 2016 18:33
@catmando Are you using Safari?
Mitch VanDuyn
@catmando
Aug 03 2016 18:33
no chrome and ff
Jamie Gaskins
@jgaskins
Aug 03 2016 18:34
Huh, weird. I haven't had trouble in Chrome, but maybe that's changed recently. I know Safari usually loads the source maps before any code is run, which can take a really long time.
If you aren't concatenating assets, you may be requesting over 100 JS assets in an Opal app. Almost 250 if you're using opal-browser.
That's without source maps enabled. With them, it's double.
Mitch VanDuyn
@catmando
Aug 03 2016 18:35
don't forget we have reactrb, reactive-record, reactrb-router, synchromesh, etc
I know I mentioned this a long time ago, but it seems like you get source maps (or you used to) for gems...
Jamie Gaskins
@jgaskins
Aug 03 2016 18:35
Exactly. In development, your app is probably only serving 1 request at a time, so you're looking at hundreds of synchronous HTTP requests.
Mitch VanDuyn
@catmando
Aug 03 2016 18:36
but what changed between 0.8 and 0.9?
Jamie Gaskins
@jgaskins
Aug 03 2016 18:36
Better source map support, I think.
Mitch VanDuyn
@catmando
Aug 03 2016 18:36
gotcha
Jamie Gaskins
@jgaskins
Aug 03 2016 18:36
So it may take a few ms longer to process each source map, but over a couple hundred requests, that adds up.
Mitch VanDuyn
@catmando
Aug 03 2016 18:37
so I am thinking I could poke around and see if we can get it switched off for gems, or somehow precompile the gem assets or something...
but even in our main app we have several hundred component files.
Jamie Gaskins
@jgaskins
Aug 03 2016 18:38
Yeah, if we could whitelist just app code for source maps, that would be quite helpful.
Mitch VanDuyn
@catmando
Aug 03 2016 18:39
yeah, and perhaps even white list or cache files that are not changing...
Jamie Gaskins
@jgaskins
Aug 03 2016 18:39
Sprockets caching is pretty good, so it's probably already doing some of that, but if we could HTTP-cache it so the request isn't even made, that would be even better.
Mitch VanDuyn
@catmando
Aug 03 2016 18:40
right
it could also be something with my test setup that is not helping
CJ Lazell
@cj
Aug 03 2016 20:01
Is there anyway using sprockets/opal that I can remove everything inbetween module ServerMethods; end before it’s compiled?
Jamie Gaskins
@jgaskins
Aug 03 2016 20:03
@cj Besides using if RUBY_ENGINE == 'opal'?
CJ Lazell
@cj
Aug 03 2016 20:04
yee. It’s just to make the syntax cleaner
Mitch VanDuyn
@catmando
Aug 03 2016 20:15
its pretty flexible, so you can you can say something like this:
module ServerMethods
 ...
end unless RUBY_ENGINE == 'opal'
or you can put ServerMethods in a file that you only bring in include on the server
CJ Lazell
@cj
Aug 03 2016 20:17
yee, I knew that. (and that’s what I’m currently doing). It would just look a lot nicer, not having to do that
Mitch VanDuyn
@catmando
Aug 03 2016 20:17
what would look better for example?
CJ Lazell
@cj
Aug 03 2016 20:18
not having to write unless RUBY_ENGINE == 'opal’ at the end and it still not compile what is inbetween
Jamie Gaskins
@jgaskins
Aug 03 2016 20:21
So you want there to be no indication in the Ruby code that it isn't getting compiled?
CJ Lazell
@cj
Aug 03 2016 20:21
well that’s what module ServerMethods implys already
there is no reason you’d want server methods compiled to the client :)
I’m creating a gem called Akin. “Akin is a plugin system that is compatible client side, thanks to Opal.”. So it’s for a single code base that runs on the server and client, using the same plugin arcetecture as roda.
Jamie Gaskins
@jgaskins
Aug 03 2016 20:25
Right, but syntax wise you want it to be completely magical?
CJ Lazell
@cj
Aug 03 2016 20:26
It would be magical in the sense, anthing inbetween module ServerMethods wouldn’t get compiled client side, yes
Jamie Gaskins
@jgaskins
Aug 03 2016 20:26
It seems like the only way it'd be possible is to allow you to hook into the code generator in the compiler.
… which I don't believe is possible.
CJ Lazell
@cj
Aug 03 2016 20:27
that’s what I was afraid of, or having to use my own fork
Jamie Gaskins
@jgaskins
Aug 03 2016 20:27
Mostly because I think it would require checks for hooks into every single type of node that's hookable.
Right now, each type of node in the compiler just emits code directly. I don't think there's any instrumentation available for it.
Ilya Bylich
@iliabylich
Aug 03 2016 20:36
@cj Which version of Opal are you using?
Mitch VanDuyn
@catmando
Aug 03 2016 20:36
so this would only work with module ServerMethods
Does anybody know why JSON.parse('Foo') changed which exception was raised in 10.0? pre 10.0 it raised StandardError, now it raises some other exception...
Ilya Bylich
@iliabylich
Aug 03 2016 20:43
@cj @jgaskins Opal master allows you to add you own AST rewriter - https://github.com/opal/opal/blob/master/lib/opal/rewriter.rb
CJ Lazell
@cj
Aug 03 2016 20:44
o wow… nice! thank you for pointing that out :)
Ilya Bylich
@iliabylich
Aug 03 2016 20:45
@cj It's possible if you are on the latest master. This is how Opal handles if RUBY_ENGINE == 'opal' - https://github.com/opal/opal/blob/master/lib/opal/rewriters/opal_engine_check.rb
Jamie Gaskins
@jgaskins
Aug 03 2016 20:45
Whoa, slick.
I didn't realize anything like this had been added.
Mitch VanDuyn
@catmando
Aug 03 2016 20:45
@cj - the way reactive-record does this is by having a directory models/public where any isomorphic models go, and are compiled for both server and client, models not in that directory only live on the server
Jamie Gaskins
@jgaskins
Aug 03 2016 20:45
Admittedly, it's been a little while since I've paid much attention to the commit log.
Mitch VanDuyn
@catmando
Aug 03 2016 20:47
@cj the other approach you might find interesting I use in test harnesses where I have methods like on_client do ... and isomorphic do ...
on_client take the block turns it back into a string, then feeds it to opal, and includes it in the manifest. isomorphic does the same thing but first does a local eval of the block.
CJ Lazell
@cj
Aug 03 2016 20:49
@catmando inteeresting, is that in reactive-record? I’ll take a look
Mitch VanDuyn
@catmando
Aug 03 2016 20:49
this way you can dynamically construct code blocks in the rspecs. You might find that interesting
@cj - which the models/public thing, or the on_client thing?
CJ Lazell
@cj
Aug 03 2016 20:49
on_client thing
Mitch VanDuyn
@catmando
Aug 03 2016 20:49
no I developed that after most of the reactive-record tests were done
CJ Lazell
@cj
Aug 03 2016 20:50
ah k, do you have a link to that code?
Mitch VanDuyn
@catmando
Aug 03 2016 20:50
it is used on the v2-4-0 branch of reactrb-router
CJ Lazell
@cj
Aug 03 2016 20:50
cheers, I’ll check it out
I would love somebody to clean up these helpers and make a gem hint hint!
CJ Lazell
@cj
Aug 03 2016 20:53
^link doesn’t work
Mitch VanDuyn
@catmando
Aug 03 2016 20:53
yes it does :-)
(because I fixed it)
CJ Lazell
@cj
Aug 03 2016 20:53
ah, now it does :)
Mitch VanDuyn
@catmando
Aug 03 2016 21:00
anyway as far as the JSON thing goes this seems like a bug:
in IRB:
JSON.parse('foo') rescue 'foo'
works
in opal < 0.10 works
but in opal ~0.10.x it throws a different (no StandardError) error.
of course RuboCop doesn't like you to rescue Exception, i'll raise an issue and hopefully get around to a PR...
Ilya Bylich
@iliabylich
Aug 03 2016 21:08
@catmando It can be related to the changes in the default behavior of rescue. As far as I remember, before 0.10 rescue caught Exception by default (which is obviously wrong). Now it handles only subclasses of StandardError
JSON.parse throws a native JS Error which equals to Opal's Exception
Mitch VanDuyn
@catmando
Aug 03 2016 21:09
ahhh so perhaps JSON never raised StandardError
Ilya Bylich
@iliabylich
Aug 03 2016 21:09
yep
Mitch VanDuyn
@catmando
Aug 03 2016 21:09
well, to fix it everything will have to get wrapped and then throw the proper error... is anybody going to have a problem with that?
CJ Lazell
@cj
Aug 03 2016 21:50
I love wraps :)