Skip to content

Commit

Permalink
perf: Switch LensVM to wasmtime runtime (sourcenetwork#2030)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves sourcenetwork#2029

## Description

Switches LensVM to the wasmtime runtime.

Should be a fair bit faster than wazero, and supports all the important
build targets. Also doesn't suffer from
tetratelabs/wazero#1818

Note on [wasmtime-go](https://github.com/bytecodealliance/wasmtime-go):
> This Go library uses CGO to consume the C API of the [Wasmtime
project](https://github.com/bytecodealliance/wasmtime) which is written
in Rust. Precompiled binaries of Wasmtime are checked into this
repository on tagged releases so you won't have to install Wasmtime
locally, but it means that this project only works on Linux x86_64,
macOS x86_64 , and Windows x86_64 currently. Building on other platforms
will need to arrange to build Wasmtime and use CGO_* env vars to compile
correctly.

This is different to wazero, which as a pure Go project supports pretty
much anything Go does without messing about.
  • Loading branch information
AndrewSisley authored and shahzadlone committed Jan 20, 2024
1 parent 9dc6cd2 commit be88f58
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-and-upload-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
runs-on: ${{ matrix.os }}

env:
CGO_ENABLED: 1
DEFRA_CLIENT_GO: ${{ matrix.client-type == 'go' }}
DEFRA_CLIENT_HTTP: ${{ matrix.client-type == 'http' }}
DEFRA_CLIENT_CLI: ${{ matrix.client-type == 'cli' }}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-log/v2 v2.5.1
github.com/jbenet/goprocess v0.1.4
github.com/lens-vm/lens/host-go v0.0.0-20230729032926-5acb4df9bd25
github.com/lens-vm/lens/host-go v0.0.0-20231108161805-be145dd591bb
github.com/libp2p/go-libp2p v0.32.1
github.com/libp2p/go-libp2p-gostream v0.6.0
github.com/libp2p/go-libp2p-kad-dht v0.25.1
Expand Down Expand Up @@ -57,6 +57,7 @@ require (
github.com/Jorropo/jsync v1.0.1 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytecodealliance/wasmtime-go/v14 v14.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
Expand Down Expand Up @@ -168,7 +169,6 @@ require (
github.com/spf13/cast v1.5.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tetratelabs/wazero v1.3.1 // indirect
github.com/textileio/go-log/v2 v2.1.3-gke-2 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/x448/float16 v0.8.4 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBT
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40Nwln+M/+faA=
github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM=
github.com/bytecodealliance/wasmtime-go/v14 v14.0.0 h1:ur7S3P+PAeJmgllhSrKnGQOAmmtUbLQxb/nw2NZiaEM=
github.com/bytecodealliance/wasmtime-go/v14 v14.0.0/go.mod h1:tqOVEUjnXY6aGpSfM9qdVRR6G//Yc513fFYUdzZb/DY=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -360,8 +362,8 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lens-vm/lens/host-go v0.0.0-20230729032926-5acb4df9bd25 h1:hC67vWtvuDnw8w6u4jLFoj3SOH92/4Lq8SCR++L7njw=
github.com/lens-vm/lens/host-go v0.0.0-20230729032926-5acb4df9bd25/go.mod h1:rDE4oJUIAQoXX9heUg8VOQf5LscRWj0BeE5mbGqOs3E=
github.com/lens-vm/lens/host-go v0.0.0-20231108161805-be145dd591bb h1:e/9Oqk71LAu/qADRkDMgJAvb52CU1Ks27GBsIdaqW1c=
github.com/lens-vm/lens/host-go v0.0.0-20231108161805-be145dd591bb/go.mod h1:RNLpJkOAuqT392hxxz0FQiMiEd3pY8eI5s1AUEPAOeE=
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c=
Expand Down Expand Up @@ -600,8 +602,6 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tetratelabs/wazero v1.3.1 h1:rnb9FgOEQRLLR8tgoD1mfjNjMhFeWRUk+a4b4j/GpUM=
github.com/tetratelabs/wazero v1.3.1/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
github.com/textileio/go-datastore-extensions v1.0.1 h1:qIJGqJaigQ1wD4TdwS/hf73u0HChhXvvUSJuxBEKS+c=
github.com/textileio/go-ds-badger3 v0.1.0 h1:q0kBuBmAcRUR3ClMSYlyw0224XeuzjjGinU53Qz1uXI=
github.com/textileio/go-log/v2 v2.1.3-gke-2 h1:YkMA5ua0Cf/X6CkbexInsoJ/HdaHQBlgiv9Yy9hddNM=
Expand Down
4 changes: 2 additions & 2 deletions lens/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/lens-vm/lens/host-go/config"
"github.com/lens-vm/lens/host-go/config/model"
"github.com/lens-vm/lens/host-go/engine/module"
"github.com/lens-vm/lens/host-go/runtimes/wazero"
"github.com/lens-vm/lens/host-go/runtimes/wasmtime"
"github.com/sourcenetwork/immutable"
"github.com/sourcenetwork/immutable/enumerable"

Expand Down Expand Up @@ -104,7 +104,7 @@ func NewRegistry(lensPoolSize immutable.Option[int], db TxnSource) client.LensRe
db: db,
registry: &lensRegistry{
poolSize: size,
runtime: wazero.New(),
runtime: wasmtime.New(),
modulesByPath: map[string]module.Module{},
lensPoolsBySchemaVersionID: map[string]*lensPool{},
reversedPoolsBySchemaVersionID: map[string]*lensPool{},
Expand Down

0 comments on commit be88f58

Please sign in to comment.