Giter Site home page Giter Site logo

async-load-fn PARALLEL loading about sci HOT 9 CLOSED

awb99 avatar awb99 commented on June 4, 2024
async-load-fn PARALLEL loading

from sci.

Comments (9)

borkdude avatar borkdude commented on June 4, 2024

Sounds like something that might cause multiple request for the same namespace as one namespace might load another one. This is why they are loaded in order (same as in Clojure on the JVM for example).

from sci.

borkdude avatar borkdude commented on June 4, 2024

Btw feel free to poke around in sci/async.cljs if you wish.

from sci.

awb99 avatar awb99 commented on June 4, 2024

sci loads each namespace that has not been loaded ONCE. This works fine. Say I want to render a page, that should
get lazy-loaded because it will require lots of render-functions that are huge (vega, highcharts, aggrid, etc). So I put
the page into its own namespace, and all the render-functions are in the ns requires. Typically I also would add 5-10
namespaces that are written in interpreted sci clojure. Utility functions, etc. So this would require then say 10 namespaces,
and the requiring process is SERIAL. So it would first asynchronously require the first namespace in the (:require) list.
Then it would require the second namespace, etc. If there are 10 such namespaces, and the roundtrip time to the server
is 200ms, then this means I need 2 seconds to load that page.

from sci.

borkdude avatar borkdude commented on June 4, 2024

sci loads each namespace that has not been loaded ONCE. This works fine.

Currently, yes, exactly BECAUSE requires are serialized.

from sci.

borkdude avatar borkdude commented on June 4, 2024

then this means I need 2 seconds to load that page

Normally responses from servers can be cached though so after caching it should load very quickly.

from sci.

awb99 avatar awb99 commented on June 4, 2024

The server is replying FAST. This is not the issue. The issue is that sci sends one request, then waits for the answer. The the next request, then wait for the second request, etc. What kills me is the ROUNDTRIP time to the server. If sci would send
all the async-load-fn request AT ONCE, then in 200ms all requests are processed. But if say 10 ns requests are send one after
another, then the wait time is 10*200ms = 2 seconds.

from sci.

awb99 avatar awb99 commented on June 4, 2024

Perhaps I should elaborate a little bit how I use sci. So I use shadow-cljs for clojurescript modules that get compiled into js bundle (or separate js modules if they are big). I expose to the sci context all namespaces of compiled clojurescript with the same
name as they are in clojurescript. You do it the same way with sci-configs. This has a huge advantage: one can develop apps in only interpreted sci clojure(script). And if at some point there is enough complexity that warrants compilation with shadow-cljs, then it is very easy to change it so that this namespaces instead of being interpreted by sci are compiled by shadow-cljs. The big advantage of using sci is (other than it allows users to extend the website at runtime in a dynamic fashion) that the lazy-loading of compiled cljs-js-bundles is completely transparent to the user. But the flipside is that the (ns (:require)) can become big.

from sci.

awb99 avatar awb99 commented on June 4, 2024

sci async-load-fn:
https://github.com/pink-gorilla/goldly/tree/master/goldly/src/goldly/sci/loader
I load lazy-shadow-cljs-modules and sci-cljs-sources that get interpreted.

from sci.

borkdude avatar borkdude commented on June 4, 2024

The server is replying FAST. This is not the issue.

This is not the point. If responses of assets (.js files) are cached, a request shouldn't even take a 1 millisecond. It seems you should fix that problem first.

As I said, feel free to explore parallel loading, the code is in sci/async.cljs but I don't think it's actually a great idea and I have the feeling that it could create issues. What could for example happen:

(ns a (:require [foo] [bar] [baz]))

(ns foo (:require [bar] [baz]))

For namespace a we get three parallel requests, requesting foo and bar, but as soon as foo comes back, we're also going to request bar and baz. Suppose bar contains top level side effects. We have no way to prevent that side effect from happening multiple times instead of only once. Also you're creating more requests (5) instead of the actual amount necessary (3).

from sci.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.