Skip to content
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

[WIP] Use Task.Run instead ThreadPool.QueueUserWorkItem #18

Closed
wants to merge 4 commits into from

Conversation

danipen
Copy link
Owner

@danipen danipen commented May 16, 2022

Fixes #9

@danipen
Copy link
Owner Author

danipen commented Oct 23, 2022

Some progress. I was able to have a working POC:
avaloniaedit-wasm

I basically compiled oniguruma using emcc:

autoreconf -vfi
emconfigure ./configure
emmake make

and included the native references into the WebAssembly project as NativeFileReference.

<ItemGroup>
    <NativeFileReference Include="libonig.a" />
    <NativeFileReference Include="onigwrap.c" />
</ItemGroup>

However, I have no idea about how to generate a nuget for TextmateSharp supporting wasm.

Issues:

  • It's quite slow scrolling.
  • And the worst ... unfortunately the parsing cannot be done in the background since wasm is not supporting background threads/tasks (it hangs the UI). The TMModel should be refactored to split the work into small chunks to avoid blocking the UI since ultimately, its running single-threaded. Not sure if dotnet wasm is going to support multithreading soon...

@danipen danipen changed the title Use Task.Run instead ThreadPool.QueueUserWorkItem [WIP] Use Task.Run instead ThreadPool.QueueUserWorkItem Oct 23, 2022
@Numpsy
Copy link
Contributor

Numpsy commented Oct 23, 2022

However, I have no idea about how to generate a nuget for TextmateSharp supporting wasm.

I'm a total beginner with web assembly so I can't speak from experience, but there are a few docs at https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly-native-dependencies?view=aspnetcore-6.0#package-native-dependencies-in-a-nuget-package about how it might be done, and I've seen mention elsewhere of using the 'browser-wasm' identifier to include the binaries in a nuget package.

From the links on tha MS article, there is a 'SkiaSharp.NativeAssets.WebAssembly' package that contains the Wasm build of Skia, and a 'SkiaSharp.Views.Blazor' which contains MSBuild files which add the 'NativeFileReference' entries for the .a files, which might be an example of how the properties can be set up?

@danipen
Copy link
Owner Author

danipen commented Oct 23, 2022

Yes, I tried this here, with no luck. Not sure if here I need to add the .wasm or the .a file in the nuget.

  • If what I need is to include the .wasm file as a reference, I'm not sure about how to generate it.
  • If what I need is to include the .a, I'm not sure how I can later explicitly tell it's a native reference to the wasm project.

@Numpsy
Copy link
Contributor

Numpsy commented Oct 23, 2022

There's a note in that MS documentation that says

Prebuilt dependencies typically must be built using the same version of Emscripten used to build the .NET WebAssembly runtime.

So I don't know if distributing the .wasm file is safe there?

For (2), Can you put a TextMateSharp.props file inside the 'build' directory in the nuget package which contains the NativeFileReference item? e.g. in The SkiaSharp/Blazor package it has:

image

(However, I'm not sure what the conditions and such should be to control when it's included)

@danipen
Copy link
Owner Author

danipen commented Oct 24, 2022

So it seems I need to ship these two files in the nuget...

libonig.a
onigwrap.c

I only need to ship them for browser-wasm platform ...and I need to include as NativeFileReference for the project being built.

Honestly...im not sure about the syntax to do that docs are not very verbose.

@danipen
Copy link
Owner Author

danipen commented Oct 24, 2022

@Numpsy good news! I got it working here! #36

@danipen
Copy link
Owner Author

danipen commented Oct 24, 2022

I'll discard this PR.

@danipen danipen closed this Oct 24, 2022
@danipen
Copy link
Owner Author

danipen commented Oct 24, 2022

For the threading issue, it seems that is going to be supported in .net 7 via WasmEnableThreads ...

<PropertyGroup>
  <WasmEnableThreads>true</WasmEnableThreads>
</PropertyGroup>

https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-7-rc-2/#webassembly-multithreading-experimental

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.Threading.Thread.Start not supported on webassembly
2 participants