These are chat archives for opal/opal

12th
Oct 2017
Colin Gunn
@balmoral
Oct 12 2017 01:01
@/all Anyone know how to enable source maps with Roda opal assets? Might be an opal tilt option.
Jamie Gaskins
@jgaskins
Oct 12 2017 02:17
@balmoral Do you mean the :assets plugin that comes with Roda or the roda-opal_assets gem?
Colin Gunn
@balmoral
Oct 12 2017 02:19
@jgaskins yes - the :assets plugin provides :js_opts which get passed to tilt, but I’ve no idea where to start with that. I’ve tried Opal::Config.source_map_enabled = true before setting up the Opal::Builder and calling the plugin, but no luck.
@jgaskins oh sorry - not not the roda-opal_assets gem, just straight usage of Roda for roda-opal-example
Jamie Gaskins
@jgaskins
Oct 12 2017 02:21
To be honest, I haven't had much success with the :assets plugin. I never got it to work with require. :-\ So it seems to be great if you load all your Opal dependencies and then all of your individual assets separately.
This might get you what you need, though https://github.com/clearwater-rb/roda-opal_assets
Colin Gunn
@balmoral
Oct 12 2017 02:26
require seems to work ok with my example. I’ve even moved some code out of assets/js and into a lib folder, with a stub assets/js/main.rb file which requires, say, lib/client/app.rb. And got :dependencies going so any file changes get past the caching. I’ll check out roda-opal_assets again. Thanks for you help.
Jamie Gaskins
@jgaskins
Oct 12 2017 02:27
Nice. I'd be happy to hear how you got that working some time :-)
Colin Gunn
@balmoral
Oct 12 2017 02:40
Very early days, but here’s what I’ve got so far: https://github.com/balmoral/roda-opal-example.git
It would be nice to have a Roda plugin which handles opal/ruby explicitly. A bit beyond my pay grade at present :smile:
Jan Biedermann
@janbiedermann
Oct 12 2017 06:29
@catmando @elia @fkchang i would like to add some numbers to the performance issue:
changing a file within a set 10 that is require_tree 'component' in rails sprockets: 6 seconds
compiling that set of 10 files with Opal::Compiler from irb: 0.026 seconds
Its NOT the compiler being slow. Now even if you add some file and cache checks to that 0.026 seconds, and maybe concatenate 3 megabytes of cached code -> 6 seconds is faaaar, faaaaaaaar awaahaay ...
Elia Schito
@elia
Oct 12 2017 08:07

@janbiedermann nice benchmark, did you try with Opal::Builder too? is require 'opal' part of the benchmark for the two cases?

If the answer to the latter question is yes I think we should report it to the sprockets team…

Jan Biedermann
@janbiedermann
Oct 12 2017 09:51

@elia @catmando i just identified part of the problem, makes me wanno freak out, wtf?:
in sprockets-3.7.1/lib/sprockets/uri_utils.rb, def split_file_uri(uri), commenting out this:

      # Hack for parsing Windows "file:///C:/Users/IEUser" paths
      path.gsub!(/^\/([a-zA-Z]:)/, '\1'.freeze)

reduces load time (without compilation) from 3 to 1,5 seconds, i will report this for sure

Elia Schito
@elia
Oct 12 2017 09:51
:rocket:
Jan Biedermann
@janbiedermann
Oct 12 2017 12:37
@elia another issue is, that with opal, the entire ruby load_path becomes an asset load_path to, now sprockets walks all those directories looking for file changes, thousands of directories and files, with File.stat, which is slow. To make it fast, it should only check the files within the app for changes, maybe that would be the task for opal-rails or opal-sprockets to limit sprockets in that way, not sure how to achieve this. How can i achieve this?
Elia Schito
@elia
Oct 12 2017 12:39
@janbiedermann that's something that actually would help sprockets perfs for any project/compiler, I mean being able to make it stat files only in some dirs and consider other directories as "static".
Jan Biedermann
@janbiedermann
Oct 12 2017 12:41
alright, checking out sprockets ...
Elia Schito
@elia
Oct 12 2017 12:42
:turtle:
:turtle:
:turtle:
:turtle:
@janbiedermann just to add some info, I think in rails 5 sprockets should rely on the file watcher to detect changes, not 100% sure tho
Jan Biedermann
@janbiedermann
Oct 12 2017 13:59

@elia @catmando, just to verify this sprockets thing i gorilla patched
sprockets-3.7.1/lib/sprockets/path_utils.rb with

  module PathUtils
    extend self

    def stat(path)
      root = '/put/rails/root/path/here/app'
      if (path[0..(root.size-1)] != root)
        @@gorilla_patch_cached_stats ||= {}
        return @@gorilla_patch_cached_stats[path] if @@gorilla_patch_cached_stats.has_key?(path)
        @@gorilla_patch_cached_stats[path] = if File.exist?(path)
                                              File.stat(path)
                                            else
                                              nil
                                             end
      else
        if File.exist?(path)
          File.stat(path)
        else
          nil
        end
      end
    end

Results:
normal get of page with stock Sprockets 3.7.1: 4 seconds
with my 2 gorilla patches:

483ms

of which in sprockets 0.2s :) :rocket:
on second page load

Elia Schito
@elia
Oct 12 2017 14:40
:bomb: :clap:
Elia Schito
@elia
Oct 12 2017 14:45
@janbiedermann I'm copying the patch to my current project right now :smile:
Jan Biedermann
@janbiedermann
Oct 12 2017 14:47
Please express your primal urge here: rails/sprockets#504
Elia Schito
@elia
Oct 12 2017 15:01
@janbiedermann any reason for this if path[7..9].include?(':') not being this if path[9] == ':'?
Jan Biedermann
@janbiedermann
Oct 12 2017 15:01
thats just because i don't know if its possible to have /c: //c: or ///c:, i was to lazy to check
if only that 9 case is legal, perfect :), is it?
Elia Schito
@elia
Oct 12 2017 15:03
👍🏼 my guess is that the protocol is [a-z]+:// and only the third slash acts as root indicator
Jan Biedermann
@janbiedermann
Oct 12 2017 15:03
oh, right, makes sense :+1:
Elia Schito
@elia
Oct 12 2017 15:03
let's see what they say…
Forrest Chang
@fkchang
Oct 12 2017 18:25
@janbiedermann re: the windows gsub, maybe we only do that if the platform is windows, then at least the linux/osx users won't have that
but good work
Jan Biedermann
@janbiedermann
Oct 12 2017 18:29
@fkchang i agree, this path[9] == ':' comes almost for free, so if there is a ':' its windows, how else would you check?
Forrest Chang
@fkchang
Oct 12 2017 18:44
@janbiedermann for recent rubies something like this would work
require 'rbconfig'
@platform = case RbConfig::CONFIG['host_os']
           when /darwin/
              OSX
           when /win/
              WINDOWS
end
Jan Biedermann
@janbiedermann
Oct 12 2017 18:44
great, thanks, i will try
Adrian Madrid
@aemadrid
Oct 12 2017 20:12
I can’t seem to get Opal-Console to work
in the Chrome console I can get Opal.RUBY_VERSION = “2.2.7” but I get the Opal not running or older than 0.7 - Console not supported for this page in the Opal-Console
Forrest Chang
@fkchang
Oct 12 2017 21:22
@aemadrid it works, but there's something I need to fix with newer opal, ignore the message and type this in to handle a formatting bug
 OpalConsole.config.auto_pretty_print = false
@aemadrid I need to get around to fixing that
Elia Schito
@elia
Oct 12 2017 22:06
@janbiedermann @fkchang re windows: I think RbConfig::CONFIG['host_os'] can have different values for mingw, cygwin, and other windows variants
Adrian Madrid
@aemadrid
Oct 12 2017 22:27
@fkchang that worked! I had to do it a couple times though because I was getting errors like Exception: TypeError: Cannot read property '$==' of undefined
but doing it again usually solved that