These are chat archives for opal/opal

15th
Oct 2017
Jamie Gaskins
@jgaskins
Oct 15 2017 04:04
Weird. I don't understand why you and I would be seeing such different performance, then.
Colin Gunn
@balmoral
Oct 15 2017 04:35

Does anyone know of problems with condional requires using sprockets for testing RUBY_PLATFORM indirectly?

I’m using a Platform module which goes like:

  module Platform
    module_function

    def opal?
      RUBY_PLATFORM == 'opal'
    end

    def client?
      opal?
    end

    def server?
      !opal?
    end
  end

If I use this like

if Platform.client?
   require ‘client_code.rb’
else
  require ‘server_code.rb’
end

then opal sprockets loads server_code.rb when RUBY_PLATFORM is ‘opal’.

If I use

if RUBY_PLATFORM == ‘opal'
   require ‘client_code.rb’
else
  require ‘server_code.rb’
end

it works ok.

Jan Biedermann
@janbiedermann
Oct 15 2017 05:58
@jgaskins for your clearwater_roda_example, the load_path is to small, to make a difference. increase load_path size, and loaded set, and sprockets will become a problem. You have just 6 load_paths to look things up, with rails and hyperloop there are hundreds of load paths and over 340 .rb files compiled.
Colin Gunn
@balmoral
Oct 15 2017 08:20
@jgaskins FYI I’ve given up on roda assets plugin (couldn’t get source maps going) and I’ve switched to roda-opal_assets type setup. I don’t much like putting my ruby code under assets/js so have structured it under lib/client, lib/common, lib/server... Thanks for a great example of how to pull all this stuff together.
Torsten Rüger
@rubydesign
Oct 15 2017 08:47
@balmoral As far as i understood, the test for RUBY_PLATFORM is a compile time thing. Bit like #ifdef in the c days. So the compiler removes the appropriate require completely. If do the test in code (indirectly) both requires are included to be able to perform both branches at runtime.
Jan Biedermann
@janbiedermann
Oct 15 2017 10:30
@elia check current rails/sprockets#506, sprockets uses an internal cache, hardcoded to 1024 entries, which is far to little for ruby-hyperloop or any other large opal-rails project. constant cache misses where the result, rails/sprockets#506 now fixes this and gives me unbelieavable good numbers with opal, also for recompiles :)
Elia Schito
@elia
Oct 15 2017 20:57
@balmoral, @dancinglightning is right, that check is done at compilation level so the constant must be used explicitly, the only alternatives that comes to mind are:
  • to require the same filename but have different include paths for server & client, that can lead to some confusion
  • to keep the code as is and configure opal to ignore load errors (setting dynamic_require_severity to ignore), the con here is that you may miss some actual error in your app
Elia Schito
@elia
Oct 15 2017 22:27
@janbiedermann good catch! As a matter of fact our main app was hitting both the memstore (1024 entries) and the filestore limit (25MB) putting the latter under constant sprockets-GC pressure. Thanks a lot for looking into this, I’ll add this feedback to the PRs too first thing Monday morning 👍🏻👍🏻👍🏻
Colin Gunn
@balmoral
Oct 15 2017 23:02
Thanks @dancinglightning and @elia for the explanation. Was only a semantic nicety, so great loss. :smile: