hyperstack-org / hyperstack

Hyperstack ALPHA https://hyperstack.org
https://docs.hyperstack.org
MIT License
540 stars 41 forks source link

Hyperstack hotloader is too slow #414

Open lionelchauvin opened 3 years ago

lionelchauvin commented 3 years ago

The hotloader client is very slow when large js files are generated (hyperstack 1.0.0alpha1.8). Chrome freezes just after page loading.

With chrome profiler, I can see it stays several seconds in ruby/hyperstack-config/lib/hyperstack/hotloader/stack-trace.js in _findFunctionName and _findSourceMappingURL

hotloader profiling

These methods create Regexps each time they are called. If you keep these regexps in a cache the hotloader should be faster.

lionelchauvin commented 3 years ago

The hotloader was made for rails 5. In this version, sprockets created one .js per hyperstack/.rb file. In rails 6 all files are merged in a single application.debug-.js file. Every time a function name must be found at a specific line, application.debug-*.js is splitted on \n. On my projet it does that >300 times.

lionelchauvin commented 2 years ago

When a .rb file is changed on disk, it is sent to the browser via websocket and it is compiled by opal with Opal.compile. Another performance issue is due to the parsing of strings by opal/parser. It is very slow. Some files of my project can take 20 seconds to be compiled. I patched the hotloader in order to compile it server side and send the javascript result to the browser. The same file can be hotloaded in 0.3 seconds.