Job System + WebGL

What’s the current status of the Job System in WebGL builds (asm.js or WebAssembly)? What I’ve observed, in 2018.1b11:

  • IJobParallelFor works as expected in standalone builds and the editor, as long as I call job.Schedule().
  • Switch build type to WebGL, and jobs don’t execute. They seem to silently fail – even though I call jobHandle.Complete() in LateUpdate, the contents of the NativeArray the job modifies remain unmodified.
  • Add an explicit JobHandle.ScheduleBatchedJobs() and everything works, but it seems to run computation on the main JS thread.

Is this intended? I don’t mind wrapping a JobHandle.ScheduleBatchedJobs in a conditional for WebGL, but hopefully sooner or later the jobs can be offloaded to WebWorkers…

Afaik the job system is not supported for WebGL atm due to being single threaded.

But just silently failing is not nice behaviour. Can you please submit a bug report for this with a repro project and ping the case number here? Thanks!

[quote=“RSpicer, post:1, topic: 696219, username:RSpicer”]
What’s the current status of the Job System in WebGL builds (asm.js or WebAssembly)? What I’ve observed, in 2018.1b11:

  • IJobParallelFor works as expected in standalone builds and the editor, as long as I call job.Schedule().
  • Switch build type to WebGL, and jobs don’t execute. They seem to silently fail – even though I call jobHandle.Complete() in LateUpdate, the contents of the NativeArray the job modifies remain unmodified.
  • Add an explicit JobHandle.ScheduleBatchedJobs() and everything works, but it seems to run computation on the main JS thread.

Is this intended? I don’t mind wrapping a JobHandle.ScheduleBatchedJobs in a conditional for WebGL, but hopefully sooner or later the jobs can be offloaded to WebWorkers…
[/quote]So firstly I believe you should be calling JobHandle.ScheduleBatchedJobs on all platforms, not just WebGL. But yeah, as @Schubkraft says, silent failure is almost certainly not the behaviour we expect.

Secondly, what you’re describing sounds like expected behaviour to me - AFAIK we do not currently support WebWorkers, and all jobs run on the main thread (including engine jobs, not just C# jobs). If the WebGL team add WebWorkers later then I imagine that your jobs will Just Work, though looking at the WebWorkers documentation it looks like using them efficiently for the jobsystem will be a pretty difficult task, what with all the isolated context stuff.

Thank you for the reply! Sounds like the error case may be “in the Editor and Windows Standalone, jobs run when scheduled with jobInstance.Schedule(), without calling JobHandle.ScheduleBatchedJobs(),” then. I’ll submit a minimal repro case to the bug tracker tomorrow.

Did you submit that report yet? It would be much appreciated! Please reply with the case # if you do.