Fork me on GitHub
#clojurescript
<
2021-12-11
>
Drew Verlee06:12:36

I'll answer my own question tomorrow, but i can't remember what core async's behavior in the browser is under the hood. Is it all done against the main thread or are web works, or some other form of thread involved. If not, why not! it seems like browsers are finding ways for userland to do multithreaded work but in limited way. Does that seem right? I suppose i'm not asking about core async in particular here, but more of a general, question about how browsers seem to be changing and how i should be keeping up with those changes.

thheller06:12:30

no. 😛 everything happens in the one and only main thread, no workers. moving stuff into the worker is non trivial since they can't share memory with the main thread and as such would have to serialize/deserialize everything back and forth pretty much killing every performance gain in the process

☝️ 1
1
thheller06:12:18

browsers aren't changing in this regard at all

Drew Verlee06:12:09

I'm gonna do that thing people hate. Why aren't they changing, why wouldn't we want multithreading on the browser to?

thheller06:12:38

because retrofitting multi-threading into a JS runtime such as the browser is pretty much impossible

sova-soars-the-sora17:01:46

what if we just expose the threaded native runtime to a new type of "browser" 😏

Drew Verlee06:12:00

gotcha. What about webassembly?

thheller06:12:03

WASM might get some sort of threading at some point but doesn't as of now

Drew Verlee06:12:33

i suppose i need to read about Service Workers again, as i believe thats what was driving my question. I recall them being very limited, but would in time become more general.

thheller06:12:20

same thing as a regular web worker really, just that it can intercept requests done by the main thread (and other workers) and has a different lifecycle

thheller07:12:26

they are indeed very limited. even more so than regular workers I'd say since they are even more resource constrained

thheller07:12:15

due to their request intercept and lifecycle they can do more than regular workers but IMHO this is pretty much all they should ever be doing

thheller07:12:21

doing more is just asking for trouble 😛

Drew Verlee07:12:37

I feel like the docs on service workers told me one thing, and i heard another. > A service worker is a script that your browser runs in the background,

thheller07:12:23

that is the lifecylce I'm refering to yes. you install it and it runs, independent of the page you are on

Drew Verlee07:12:12

> Developers mimic 'concurrency' by using techniques like setTimeout(), setInterval(), XMLHttpRequest, and event handlers. Yes, all of these features run asynchronously, but non-blocking doesn't necessarily mean concurrency. Asynchronous events are processed after the current executing script has yielded. The good news is that HTML5 gives us something better than these hacks! from ~ https://www.html5rocks.com/en/tutorials/workers/basics/ Is the difference between concurrency and asynchronous in this context that we the developer can't control what work is being done on the main thread? e.g stop task A now do task B. I'm not used to comapring the words directly and its revealing that i don't understand one or the other.

thheller07:12:51

> but non-blocking doesn't necessarily mean concurrency

thheller07:12:55

this doesn't make sense IMHO 😛

thheller07:12:59

you should probably refer to something more current than July 26th, 2010 when reading about this stuff. this might still be accurate but a lot has happened since 😛

☝️ 1
Drew Verlee07:12:42

Well thats a link off the top link about service workers. So i guess i'm in good company if i'm confused.

thheller07:12:27

service workers didn't exist in 2010 so you won't find anything about them there. this is just all about generic web workers

Drew Verlee07:12:28

i always either go to mozilla or what ever google is calling themselves. Ah, ty for the link.

thheller07:12:09

the main downside of service workers in general is that they are again single threaded. if you do something in them that actually requires CPU time they will block for that time. if a request comes in while that work is happening it has to wait, possibly affecting the UX waiting longer for a request when it maybe didn't need to

Drew Verlee07:12:04

Yea. They seem to be a way to schedule work for later, not run it in parallel. I think the use of the term "run in the background" confused me because i assume the "forground" is the main thread. Thanks for the insight as always, i'm going to fall asleep in my chair now. ill look into this a bit more tomorrow.

thheller07:12:16

they are used for coordination of (possibly) all network access so slowing them down in any other way is bad

leif22:12:30

Is there any way to get the macros for cljs.test in self hosted (bootstrapped) clojurescript?

leif22:12:49

It seems like there's only cljs.core$macros.

leif22:12:54

And it looks like I can't just analyze test.cljc from the clojurescript repo myself because it looks like it relies on clojure.template, which is does not appear to be provided by clojurescript. (Unless I'm missing something.)

dpsutton22:12:33

i think i've seen this used for clojure.test/are? Not sure if there are any other usages. Surprised me the first time i saw it

leif22:12:26

@dpsutton Hmm... I see. I guess that file looks like its technically valid clojurescript.

leif22:12:38

So I should analyze that, and then analyze cljs.test?

dpsutton22:12:04

i don't know how clj macros interact with the analyzer to be honest

leif22:12:43

From what I can tell, it puts stuff in a :macros namespace.

leif22:12:50

Which is similar to the :defs in some ways.

leif22:12:07

But this is just based off of experimentation.

leif22:12:32

Oh, also it also seems to bind to mod_name$macros in the environment.

leif22:12:42

Anyway, I'll give it a shot, thanks.

leif23:12:44

@dpsutton Yup, looks like plopping those files into https://visr.pl and running them Just worked. So thanks. 🙂

👏 1