Code Monkey home page Code Monkey logo

Comments (13)

mathetake avatar mathetake commented on June 3, 2024 1

the performance will be not high, is it ture?

yeah, compared to c++ and Rust

BTW, do you know any projects that support go host implementation for proxy-wasm?

AFAIK, there's no project for proxy-wasm host in go

from proxy-wasm-go-sdk.

taoyuanyuan avatar taoyuanyuan commented on June 3, 2024 1

https://github.com/wasmerio/go-ext-wasm

I have try go-ext-wasm, and it only supports integer when import func. func (imports *Imports) AppendFunction

Invalid input type for the `proxy_log` imported function; given `ptr`; only accept `int32`, `int64`, `float32`, and `float64`.

I can‘t implement proxy-wasm func by go-ext-wasm.

from proxy-wasm-go-sdk.

mathetake avatar mathetake commented on June 3, 2024

First of all, TinyGo implements the mark and sweep grabage collector [link].

The allocated pointers are assigned to variables we create when we get data from the host environment. For example, you pass the pointer of retData *byte variable (created here) to proxy_get_buffer_bytes abi call. Then, IIUC, the host environment (implementation is here) call malloc with the size of required data and pass the returned pointer to the &retData variable inside the host environment. In this way, the allocated memory can be reached from WASM's vm and can be garbage collected normally.

from proxy-wasm-go-sdk.

taoyuanyuan avatar taoyuanyuan commented on June 3, 2024

thank you ,This is a good project.
Does standard Go will support GC in this issue golang/go#31105

from proxy-wasm-go-sdk.

mathetake avatar mathetake commented on June 3, 2024

Well, I am not sure about that, but the point is Go's official binary cannot be used for proxy-wasm since;

  • it does not support custom exports golang/go#25612
    • this is something to do with GOOS=js functionality which restricts host environments, and;
    • makes it impossible for us to implement proxy-wasm ABI
  • the resulting binary is huge in its size, that is critical for usage in network proxies.

from proxy-wasm-go-sdk.

taoyuanyuan avatar taoyuanyuan commented on June 3, 2024

I want my project is in go to support proxy-wasm,How can I implement proxy-wasm-go-host,such as https://github.com/proxy-wasm/proxy-wasm-cpp-host
Is it difficult or go runtime not support it?

from proxy-wasm-go-sdk.

mathetake avatar mathetake commented on June 3, 2024

host environments in Go can be implemented once we have WASM virtual machine and interpreter written in Go (e.g. https://github.com/mathetake/gasm, though mine is a kind of hobbiest one). That is a completely separated issue and nothing to do with Go's limitation for producing proxy-wasm ABI compatible wasm binary as we discussed above.

from proxy-wasm-go-sdk.

mathetake avatar mathetake commented on June 3, 2024

Just for my curiosity, is your project https://github.com/mosn/mosn ? 👀

from proxy-wasm-go-sdk.

taoyuanyuan avatar taoyuanyuan commented on June 3, 2024

Just for my curiosity, is your project https://github.com/mosn/mosn ? 👀

yes.
I have been studying wasm, I will have a try at gasm.
thank you!

from proxy-wasm-go-sdk.

mathetake avatar mathetake commented on June 3, 2024

gasm is just a toy VM for my learning purpose and it's far from completion. you'd better give it a shot to https://github.com/wasmerio/go-ext-wasm

Anyway, if there's anything I can do to mosn, let me know:)

from proxy-wasm-go-sdk.

taoyuanyuan avatar taoyuanyuan commented on June 3, 2024

First of all, TinyGo implements the mark and sweep grabage collector [link].

The allocated pointers are assigned to variables we create when we get data from the host environment. For example, you pass the pointer of retData *byte variable (created here) to proxy_get_buffer_bytes abi call. Then, IIUC, the host environment (implementation is here) call malloc with the size of required data and pass the returned pointer to the &retData variable inside the host environment. In this way, the allocated memory can be reached from WASM's vm and can be garbage collected normally.

I'm sorry,I have some confusion.
"the WASM GC" only exists as a proposal https://github.com/WebAssembly/gc.
How do WASM builded by tinyGo support GC?

from proxy-wasm-go-sdk.

mathetake avatar mathetake commented on June 3, 2024

TinyGo does not use the proposed WASM's gc but implements it at the language level (and this is how TinyGo supports GC on multiple platforms, not only on wasm)

from proxy-wasm-go-sdk.

taoyuanyuan avatar taoyuanyuan commented on June 3, 2024

TinyGo does not use the proposed WASM's gc but implements it at the language level (and this is how TinyGo supports GC on multiple platforms, not only on wasm)

(func $runtime.alloc (type 14) (param i32) (result i32)
    (local i32 i32 i32 i32 i32 i32)
    block  ;; label = @1
      local.get 0
      i32.eqz
      br_if 0 (;@1;)
      local.get 0
      i32.const 15
      i32.add
      i32.const 4
      i32.shr_u
      local.set 1
      i32.const 0
      i32.load offset=75528
      local.tee 2
      local.set 3
      i32.const 0
      local.set 4
      i32.const 0
      local.set 5
      loop  ;; label = @2
        block  ;; label = @3
          local.get 3
          local.get 2
          i32.ne
          br_if 0 (;@3;)
          local.get 5
          i32.const 255
          i32.and
          local.set 2
          i32.const 1
          local.set 5
          block  ;; label = @4
            block  ;; label = @5
              local.get 2
              i32.const 1
              i32.gt_u
              br_if 0 (;@5;)
              local.get 2
              br_table 2 (;@3;) 1 (;@4;) 2 (;@3;)
            end
            i32.const 66085
            i32.const 13
            call $runtime.runtimePanic
            unreachable
          end
          call $runtime.GC

oh, it call runtime.GC when runtime.alloc, the performance will be not high, is it ture?
BTW, do you know any projects that support go host implementation for proxy-wasm?
thank you very much!

from proxy-wasm-go-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.