-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scala.JS build with FS2? #500
Comments
@fiadliel can you perhaps try performance of processing with and w/o fs2 on node.js before we decide? I just tried that about like 6 months ago with 0.7 and performance was so poor that we had decided to trash idea. Can you do tests with fs2._ now? The idea is to compare js/js benchmark instead of js/jvm benchmark :-) |
Sure! I'll have a look at which tests either are, or can be made to be equivalent. Having some performance tests that have approximately the same effects/results across 0.8 and 0.9 would be useful for comparisons even without considering the JS aspect. |
On the topic of (Scala.)JS benchmarking, I have a library scalajs-benchmark (live demo) which you might find useful. |
A big 👍 if this could work on scala.js! Main reason would be that it would be safe for many libraries to use FS2 knowing that it won't break the stack re multi-platform. Out of curiosity, how does fs2 work on scala.js without multi-threading, etc? Or perhaps rather, what won't work? |
@inthenow hence we mostly use asynchronous code for concurrency, this will work in scala.js out of the box, but, obviously not concurrently, as js does not have multi-threading model. |
If you're interested you might be able to cook something up with WebWorkers. That'll give you real threads in JS albeit with limited access. |
Sorry, Christmas/New Year was a somewhat extended downtime this year. But I'll get back to this over the next week. @inthenow you can't do anything asynchronously, and then wait for results - it has to be a callback. So Everything else from The specifics are down to what monadic effect is being used; I could imagine something other than |
Thanks guys....I'm going to cut straight to the chase, as there is some more background: If you look at https://github.com/non/cats/issues/32 and typelevel/general#4, the general question/issues/problems of having a cool I'm perhaps beginning to think that a single api will never work...but I would love to be wrong. Anyway I don't want to suggest that cats/monifu/fs2 "merge" any work, but there's scope here for some collaboration. What do you think? CC: @stew, @tpolecat, @alexandru, @ceedubs, @milessabin + anyone else.... |
Had been CC-ed, got email :-) If you're interested in my Task implementation (see design document) which was built with Scala.js in mind, then do note that I'm thinking about splitting the project (monifu/monix) in a way that makes sense, such that one can import only the |
I'm not really sure what the current status of this, but I'd like to punt on it for now. We can revisit after 0.9 is out. Assigning the 'Later' milestone. |
The only real things you need to know regarding Scala.js and Async is that you cant wait on a Future, i.e. there is no There are some hacks for |
Personally I think that whenever you've got a conversion like And on the Javascript side, even with web-workers, you lack the semantics of |
Is anyone actually arguing that blocking is a fundamental operation? If you have |
Blocking is part of the API currently, but only the JVM is officially supported. I think it would be untidy to have methods which you realize don't work on JS because there are linkage errors. So I think the sync calls should be separated out somehow (whether via a comonad or otherwise). |
I'm not really keen on the idea of separating the blocking API from the non-blocking API. Seems like we'd be making the by far common use case of running FS2 on the JVM worse to support Scala.js. |
Yeah I think this is true, per say. Any reasonable platform with a detailed bytecode can implement So at least personally, its more of a problem with Scala.js (due to Javascript being Javascript) rather than the merit of |
There is a hack for Used with an " execute immediate context" that used to be the default for scala.js, this "works" as the underlying future must have completed to get to the await. Of course, there is no guarantee that it completes before the |
Right. This is a bit whacky, but here goes: If |
@inthenow because it's not going to work for the purposes of For a def coeval[A](task: Task[A])(implicit s: Scheduler): Coeval[Either[CancelableFuture[A], A]] = ??? |
@alexandru A while after posting the comment, I went through all the ECMA docs and came to the general conclusion that it wouldn't help either 😒 |
I don't think this is a big problem -- I would not expect many pipelines using an IO-like effect type to be shareable between JS and JVM (the available libraries, expected functionality, etc.) are completely different. People on JS just have to avoid a small set of methods, which wouldn't link anyway. Fundamentally, once a possibly asynchronous operation is actually asynchronous, we can't both handle the callback, and wait for the result, with just a single thread - impossible. And in the case of Since we can't do impossible things, I think the biggest part of the job here to have something useful (if not tidy) is to choose a test framework which actually lets us run tests asynchronously. uTest looks interesting, but it doesn't have any support for scalacheck (yet). |
ScalaTest has Scala.js support as of 3.0. I use it with Scalacheck on scodec. |
@fiadliel, folks, sorry for the spam. I like thinking about this stuff and this is a really narrow domain that other people aren't interested in :-) What follows is a brain dump :-P For testing Monix I've built Minitest which does have both integration with ScalaCheck and support for testing asynchronous computations working in Scala.js, something I believe ScalaTest still doesn't do. It's very light, which is a feature I think. Of course, in Monix I haven't really needed actual asynchronicity, because time itself is provided by the Scheduler and so you can fake it, non-determinism included.
The problem is that The mistake, in my opinion, is that people think of Blocking for a result is of course bad, because it's unsafe, as blocking, just like intrinsic locks, are breaking the encapsulation of the underlying platform. The Internet is filled with the misery of people experiencing deadlocks or sudden slowdowns and not knowing what's going on. Did you know that Scala's own Back to Monix's Task, you can still block for the result, but you'd have to do In Monix a Coeval is the Task-like type that always executes synchronously, as an added restriction to |
I started this work on the |
Quick progress update on the topic/sjs branch:
At this point, pure streams and basic effectful streams appear to be working fine under Scala.js. I'm going to start porting the core test suite over next. This will take a while, because all the tests will need to be changed to return a |
What do you think of having a (possibly experimental) Scala.JS build of FS2?
With Node optimization, rough ball-park speed reduction seems around 20x compared with running on the JVM :) But it does work (mostly).
Due to the lack of async support in scalacheck, it seems somewhat difficult to do any async testing, but I got the pure tests working using a non-task, non-async, Trampoline-based monad.
Task
itself works in a browser/JS context, as long as you avoidrun
/attemptRun
/etc., for obvious reasons.The text was updated successfully, but these errors were encountered: