wardite 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbf27d475ac9dac6a9c0f6284bf379858dfef4ee52f3a2d609f41e0a87110b46
4
- data.tar.gz: 69d508dc6674117a0c94e8308b357e49a05952f17ac949470c53e8a3267442c2
3
+ metadata.gz: f0d5832e8cec120cdc72a68daf9acafb4d571fa2be166a6b912536774278c634
4
+ data.tar.gz: 6527a2be1289f3d3e9223cd93497b95c1956593fea6b3430f8cd8293e4ab8e5f
5
5
  SHA512:
6
- metadata.gz: 9d1b5d0ed4b626ab9c34fd0aabedca56b48afa4e9629557e0fcc8d0c7a2e05ad57d674d630c4f4b1599ec1babf70082d2a21041890f6081d4fbe18b8e57c0789
7
- data.tar.gz: ae55bd53d03c27a6626e320223389655adcfb67033d99bf9715171eb9bb90c718fab3eacefb2e8d9dd367f7c6d5c986f2bc956741da261d821ce102362b0898e
6
+ metadata.gz: 95c24b6c6461b449270eb9a343e613095b2ee7ee587c1ebb88933c6c3c6e65bcba044b48ab51928ff2398b9b11a1d84a4830b78aeb1e67c37448900c2ffa2ddb
7
+ data.tar.gz: 4ff3a32bd496162b06df804717a3017e2bcfbdccf25a2727c2c0096cbd6aa12abd119e05b2fdea4db29aaff0f668f42ef856e8b120a685abb0b7c4765c1eb18b
data/README.md CHANGED
@@ -70,9 +70,9 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/udzura
70
70
 
71
71
  ## See also
72
72
 
73
- - https://github.com/technohippy/wasmrb?tab=readme-ov-file
73
+ - https://github.com/technohippy/wasmrb
74
74
  - Referencial implementation but no support with WASI
75
- - Wardite aims to support full WASI (previwe 1)
75
+ - Wardite aims to support full WASI (preview 1)
76
76
  - https://github.com/skanehira/chibiwasm
77
77
  - Small and consise implementation in Rust
78
78
  - Wardite was first built upon [its development tutorial](https://skanehira.github.io/writing-a-wasm-runtime-in-rust/). Thanks!
data/lib/wardite/value.rb CHANGED
@@ -8,13 +8,13 @@ module Wardite
8
8
  # @rbs value: Integer
9
9
  # @rbs return: I32
10
10
  def I32(value)
11
- I32.new(value & I32::I32_MAX)
11
+ I32.cached_or_initialize(value & I32::I32_MAX)
12
12
  end
13
13
 
14
14
  # @rbs value: Integer
15
15
  # @rbs return: I64
16
16
  def I64(value)
17
- I64.new.tap{|i| i.value = value & I64::I64_MAX }
17
+ I64.new(value & I64::I64_MAX)
18
18
  end
19
19
 
20
20
  # @rbs value: Float
@@ -40,6 +40,16 @@ module Wardite
40
40
  # when we want to access signed value, it'd be done via #value_s
41
41
  attr_accessor :value #: Integer
42
42
 
43
+ # @rbs!
44
+ # @@i32_object_pool: Hash[Integer, I32]
45
+ @@i32_object_pool = {} #: Hash[Integer, I32]
46
+
47
+ # @rbs value: Integer
48
+ # @rbs return: I32
49
+ def self.cached_or_initialize(value)
50
+ @@i32_object_pool[value] || I32.new(value)
51
+ end
52
+
43
53
  # @rbs value: Integer
44
54
  def initialize(value=0)
45
55
  @value = value
@@ -225,6 +235,12 @@ module Wardite
225
235
  def ==(other)
226
236
  return self.class == other.class && self.value == other.value
227
237
  end
238
+
239
+ (0..64).each do |value|
240
+ @@i32_object_pool[value] = I32.new(value)
241
+ end
242
+ value = -1 & I32::I32_MAX
243
+ @@i32_object_pool[value] = I32.new(value)
228
244
  end
229
245
 
230
246
  class I64
@@ -234,6 +250,11 @@ module Wardite
234
250
 
235
251
  attr_accessor :value #: Integer
236
252
 
253
+ # @rbs value: Integer
254
+ def initialize(value=0)
255
+ @value = value
256
+ end
257
+
237
258
  # @rbs str: String
238
259
  # @rbs size: Integer|nil
239
260
  # @rbs signed: bool
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Wardite
5
- VERSION = "0.6.0" #: String
5
+ VERSION = "0.6.1" #: String
6
6
  end
@@ -0,0 +1,25 @@
1
+ require "benchmark"
2
+ require "wardite"
3
+
4
+ N = 1000000
5
+
6
+ i32_100 = Wardite::I32.new(100)
7
+ i32_200 = Wardite::I32.new(200)
8
+ $RES = {}
9
+ $RES2 = {}
10
+
11
+ Benchmark.bmbm do |x|
12
+ x.report("add via value") do
13
+ N.times do |i|
14
+ res = Wardite::I32.new(i32_100.value + i32_200.value)
15
+ $RES[i%10] = res # avoid optimization
16
+ end
17
+ end
18
+
19
+ x.report("add immediate") do
20
+ N.times do |i|
21
+ res = 100 + 200
22
+ $RES2[i%10] = res
23
+ end
24
+ end
25
+ end
@@ -6,7 +6,7 @@ module Wardite
6
6
  # @rbs buf: File|StringIO
7
7
  # @rbs max_level: Integer
8
8
  # @rbs return: Integer
9
- def fetch_uleb128: (File | StringIO buf, ?max_level: Integer) -> Integer
9
+ def self?.fetch_uleb128: (File | StringIO buf, ?max_level: Integer) -> Integer
10
10
 
11
11
  # @rbs buf: File|StringIO
12
12
  # @rbs return: Integer
@@ -32,6 +32,12 @@ module Wardite
32
32
  # when we want to access signed value, it'd be done via #value_s
33
33
  attr_accessor value: Integer
34
34
 
35
+ @@i32_object_pool: Hash[Integer, I32]
36
+
37
+ # @rbs value: Integer
38
+ # @rbs return: I32
39
+ def self.cached_or_initialize: (Integer value) -> I32
40
+
35
41
  # @rbs value: Integer
36
42
  def initialize: (?Integer value) -> untyped
37
43
 
@@ -119,6 +125,9 @@ module Wardite
119
125
 
120
126
  attr_accessor value: Integer
121
127
 
128
+ # @rbs value: Integer
129
+ def initialize: (?Integer value) -> untyped
130
+
122
131
  # @rbs str: String
123
132
  # @rbs size: Integer|nil
124
133
  # @rbs signed: bool
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wardite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio Kondo
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-01-10 00:00:00.000000000 Z
10
+ date: 2025-01-13 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: A pure-ruby webassembly runtime
14
13
  email:
@@ -59,7 +58,7 @@ files:
59
58
  - lib/wardite/wasi.rb
60
59
  - lib/wardite/wasi/consts.rb
61
60
  - lib/wardite/wasm_module.rb
62
- - misc/proposals/rubykaigi2025.md
61
+ - misc/bench-value.rb
63
62
  - misc/slides/fib.c
64
63
  - misc/slides/fib.html
65
64
  - misc/slides/image-1.png
@@ -95,7 +94,6 @@ licenses: []
95
94
  metadata:
96
95
  homepage_uri: https://github.com/udzura/wardite
97
96
  source_code_uri: https://github.com/udzura/wardite
98
- post_install_message:
99
97
  rdoc_options: []
100
98
  require_paths:
101
99
  - lib
@@ -110,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
108
  - !ruby/object:Gem::Version
111
109
  version: '0'
112
110
  requirements: []
113
- rubygems_version: 3.5.11
114
- signing_key:
111
+ rubygems_version: 3.6.2
115
112
  specification_version: 4
116
113
  summary: A pure-ruby webassembly runtime
117
114
  test_files: []
@@ -1,46 +0,0 @@
1
- # RubyKaigi 2025 Proposal
2
-
3
- ## title:
4
-
5
- Implementing WASM Runtime in Ruby - ruby.wasm works on Ruby?
6
-
7
- ## Abstract
8
-
9
- <!--
10
-
11
- Create an abstract of talk in English, following below:
12
-
13
- - 作者はWarditeというRubyのWASMランタイムを開発した
14
- - WarditeはPure Rubyで、RBSに完全対応している
15
- - Warditeでruby.wasmを動かすことをマイルストーンにしており、その取り組みについて報告する。
16
- - 例えば、WASI preview 1 対応、パフォーマンス改善など。
17
-
18
- -->
19
-
20
- The author has developed a WASM runtime named Wardite, which is implemented entirely in pure Ruby and fully annotated by RBS. The primary milestone for Wardite is to successfully run ruby.wasm. This presentation will dive deeply into the various efforts and challenges encountered in reaching this milestone. Key topics will include the implementation of support for WASI preview 1, performance enhancements, and other technical advancements. Attendees will gain insights into the current status of Wardite, its architecture, and the approaches taken to eficciently implement WebAssembly runtime in Ruby. The talk aims to provide a comprehensive overview of the progress made so far and the future directions for Wardite, highlighting its potential impact on the Ruby and WebAssembly ecosystems.
21
-
22
- ## Details
23
-
24
- 現在、以下のような内容を考えています
25
-
26
- - なぜ、Warditeを作ったか?
27
- - Pure Rubyであることのメリット
28
- - cf. wazero in Go
29
- - 簡単なWarditeの紹介
30
- - 動作のデモ
31
- - Warditeの実装
32
- - WASM Core 1.0を動かすために必要な仕様の解説
33
- - 簡単な内部設計
34
- - 命令の概要
35
- - RBSによる型情報の利用
36
- - Wardite開発上の技術的チャレンジ
37
- - パフォーマンス改善の取り組み
38
- - 基本的な計測(ruby-prof、perf)
39
- - オブジェクト生成の低減・最適化
40
- - Warditeでruby.wasmを動かすための取り組み
41
- - WASI preview 1 対応
42
- - 今後の展望
43
- - 更なるパフォーマンス改善
44
- - Component 対応
45
-
46
- ## Pitch