No announcement yet.

C# to WASM

  • Filter
  • Time
  • Show
Clear All
new posts

    C# to WASM

    sorry if this question has already been raised.

    In the nearest year big players (Microsoft, Google, Mozilla) are going to present browsers with WebAssembly support (now it is in preview mode). It seems that it will be done straight after the first release of WebAssembly.

    In my opinion WebAssembly will make a revolution, which all programmers have been waiting so long. No more dirty JavaScript, native execution speed.

    So here arises the question, do you think instead of implementing C# to JS converter it is better to concentrate now on C# to WASM?

    There is no doubt that community will make a converter from WASM to JavaScript. There are to many interests from other guys (C++ to WASM to JS, Java to WASM to JS, PHP to WASM to JS, Python to WASM to JS, plus support from Apple-Mozila-Microsoft-Google, and so on). It is now even done at some point.
    Obviously Microsoft will implement C# to WASM anyway, but probably only in 3-5 years. Thus, you guys can play the same historical role as Mono and Xamarin teams did.

    This looks really cool, I was looking into WASM - it looks like there is support for asm.js -
    "V8 is optimizing WebAssembly in the TurboFan compiler, and an alternative asm.js pipeline converting asm.js to WebAssembly so that existing asm.js sites can benefit from WebAssembly ahead-of-time compilation is nearing completion."

    I was looking at asm.js - javascript is nearly designed the same way.

    so team might not need to do any but add - use asm after defining.

    Bridge.assembly("namespace1", function ($asm, globals) {
    "use strict";
    "use asm";



      Today I start trying to use Bridge.Net and see that all struct was made from method clone. I immediately come to search for webassembly related post and wish we should use webassembly and make a valuetype on stack copied properly


        Hi Thaina,

        Thanks for the comments.

        make a valuetype on stack copied properly
        Can you explain this comment further?


          geoffrey.mcgill I made a struct Vector3 { float X,Y,Z; } then write a code

          var v0 = new Vector3();
          var v1 = v0;
          There could be many way up to implementation to convert this code into a more efficient code. such as TypedArray heap or vector vec in webassembly that would make a valuetype instead of cloning an object
          Last edited by geoffrey.mcgill; 2017-09-25 @ 11:45 PM.


            geoffrey.mcgill Actually I don't know how limit webassembly can do. But if could compile this C code

            typedef {
                float X;
                float Y;
                float Z;
            } Vector3;
            Vector3 Add(Vector3 l,Vector3& r)
                l.X += r.X;
                l.Y += r.Y;
                l.Z += r.Z;
                return l;
            I wish it should output the same wasm code when I write in C#

            struct Vector3 { public float X,Y,Z; }
            static Vector3 Add(Vector3 l,ref Vector3 r)
                l.X += r.X;
                l.Y += r.Y;
                l.Z += r.Z;
                return l;
            Last edited by Thaina; 2017-06-26 @ 09:51 AM.


              As in native C#, Stucts are mutable. You can force Structs to immutable by adding the [Immutable] attribute to Stucts.


              Hope this helps.


                geoffrey.mcgill I don't mean about immutability. I want performance

                By the implementation of current, immutability object would making a reference type object and clone. Which means a stray object in the heap and cause GC to do more works. While actual struct in C# and C is valuetype that just copied on stack (and it also able to pass by ref when it needed)

                which is far more efficient for struct like Vector and Matrix that might be used more than 10000 instance in 3D webgl

                I was asking in webassembly repo how it handle C struct and people there answer that they use linear memory allocation

                So I wish would implement struct like that. Or something alike
                Last edited by Thaina; 2017-07-01 @ 04:21 AM.


                  I see very interesting topic was brought up but somehow the attention was totally diverted into different direction. It would be good to know if there are plans to support wasm in the future. I understand there is no immediate need for that. Not all browsers support it for now but it's gradually moving toward that. Besides, indeed, it looks like a perfect opportunity for the Bridge.NET team.