Commit graph

31 commits

Author SHA1 Message Date
Takashi Kokubun
024ae34e38 [ruby/erb] Version 5.0.2
e8f3e64581
2025-07-15 16:33:00 +00:00
Hiroshi SHIBATA
9dc60de4fc Fixed inconsistency gemspec location
foo.gemspec should be located under the `lib/foo` directory.
2025-07-01 14:51:09 +09:00
Takashi Kokubun
57f8dde0f2 [ruby/erb] Version 5.0.1
42f389dc45
2025-05-14 17:10:04 +00:00
Takashi Kokubun
1d3221ad28 [ruby/erb] Give up on using resolve_feature_path
Apparently `$LOAD_PATH.resolve_feature_path('erb/escape')` returns true
for miniruby but `require 'erb/escape'` fails on it.

I still don't want to check it and rescue LoadError at the same time
because the code looks too complicated. Let me just rescue LoadError for
platforms that don't build native extensions.

3081c6b20f
2025-05-13 23:54:02 +00:00
Takashi Kokubun
e8e7daa71a [ruby/erb] Reapply "Refactor the logic of require 'erb/escape'
(https://github.com/ruby/erb/pull/61)"

This reverts commit 1c9200aab0.

Now that we've bumped BASERUBY, we shouldn't need to rescue the
LoadError.

846b20fe0e
2025-05-13 23:31:02 +00:00
Takashi Kokubun
cbaf85cb32 [ruby/erb] Update the reason why we need to rescue LoadError
c2d1f82817
2025-05-13 18:23:04 +00:00
Takashi Kokubun
c71f9b8aee [ruby/erb] Revert "Refactor the logic of require 'erb/escape'
(https://github.com/ruby/erb/pull/61)"

This reverts commit 1c393aa738.

1c9200aab0
2025-05-13 18:23:04 +00:00
Takashi Kokubun
9db0704e67 [ruby/erb] Version 5.0.0
08b544cdb8
2025-05-13 18:09:08 +00:00
Takashi Kokubun
8982bbcbee [ruby/erb] Publish constant ERB::VERSION
Even cgi.gem publicly defines CGI::VERSION today. It's just weird that
ERB::VERSION is kept private at this point.

46801cbd47
2025-05-13 18:07:17 +00:00
Takashi Kokubun
4a9d46ce07 [ruby/erb] Refactor the logic of require 'erb/escape'
(https://github.com/ruby/erb/pull/61)

1c393aa738
2025-05-13 18:00:07 +00:00
Takashi Kokubun
735f28388c [ruby/erb] Support all cgi.gem versions
(https://github.com/ruby/erb/pull/60)

de9bb8c3cc
2025-05-13 17:50:05 +00:00
Nobuyoshi Nakada
311b9352a1 [ruby/erb] [DOC] Make documentation 100%
9152ce8db4
2025-05-12 13:57:24 +00:00
Aaron Patterson
8ac8225c50 Inline Class#new.
This commit inlines instructions for Class#new.  To make this work, we
added a new YARV instructions, `opt_new`.  `opt_new` checks whether or
not the `new` method is the default allocator method.  If it is, it
allocates the object, and pushes the instance on the stack.  If not, the
instruction jumps to the "slow path" method call instructions.

Old instructions:

```
> ruby --dump=insns -e'Object.new'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,10)>
0000 opt_getconstant_path                   <ic:0 Object>             (   1)[Li]
0002 opt_send_without_block                 <calldata!mid:new, argc:0, ARGS_SIMPLE>
0004 leave
```

New instructions:

```
> ./miniruby --dump=insns -e'Object.new'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,10)>
0000 opt_getconstant_path                   <ic:0 Object>             (   1)[Li]
0002 putnil
0003 swap
0004 opt_new                                <calldata!mid:new, argc:0, ARGS_SIMPLE>, 11
0007 opt_send_without_block                 <calldata!mid:initialize, argc:0, FCALL|ARGS_SIMPLE>
0009 jump                                   14
0011 opt_send_without_block                 <calldata!mid:new, argc:0, ARGS_SIMPLE>
0013 swap
0014 pop
0015 leave
```

This commit speeds up basic object allocation (`Foo.new`) by 60%, but
classes that take keyword parameters see an even bigger benefit because
no hash is allocated when instantiating the object (3x to 6x faster).

Here is an example that uses `Hash.new(capacity: 0)`:

```
> hyperfine "ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'" "./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'"
Benchmark 1: ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'
  Time (mean ± σ):      1.082 s ±  0.004 s    [User: 1.074 s, System: 0.008 s]
  Range (min … max):    1.076 s …  1.088 s    10 runs

Benchmark 2: ./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'
  Time (mean ± σ):     627.9 ms ±   3.5 ms    [User: 622.7 ms, System: 4.8 ms]
  Range (min … max):   622.7 ms … 633.2 ms    10 runs

Summary
  ./ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end' ran
    1.72 ± 0.01 times faster than ruby --disable-gems -e'i = 0; while i < 10_000_000; Hash.new(capacity: 0); i += 1; end'
```

This commit changes the backtrace for `initialize`:

```
aaron@tc ~/g/ruby (inline-new)> cat test.rb
class Foo
  def initialize
    puts caller
  end
end

def hello
  Foo.new
end

hello
aaron@tc ~/g/ruby (inline-new)> ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
test.rb:8:in 'Class#new'
test.rb:8:in 'Object#hello'
test.rb:11:in '<main>'
aaron@tc ~/g/ruby (inline-new)> ./miniruby -v test.rb
ruby 3.5.0dev (2025-03-28T23:59:40Z inline-new c4157884e4) +PRISM [arm64-darwin24]
test.rb:8:in 'Object#hello'
test.rb:11:in '<main>'
```

It also increases memory usage for calls to `new` by 122 bytes:

```
aaron@tc ~/g/ruby (inline-new)> cat test.rb
require "objspace"

class Foo
  def initialize
    puts caller
  end
end

def hello
  Foo.new
end

puts ObjectSpace.memsize_of(RubyVM::InstructionSequence.of(method(:hello)))
aaron@tc ~/g/ruby (inline-new)> make runruby
RUBY_ON_BUG='gdb -x ./.gdbinit -p' ./miniruby -I./lib -I. -I.ext/common  ./tool/runruby.rb --extout=.ext  -- --disable-gems  ./test.rb
656
aaron@tc ~/g/ruby (inline-new)> ruby -v test.rb
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin24]
544
```

Thanks to @ko1 for coming up with this idea!

Co-Authored-By: John Hawthorn <john@hawthorn.email>
2025-04-25 13:46:05 -07:00
wanabe
272a8c3c3f [ruby/erb] Make @scanner_map of ERB::Compiler::Scanner ractor-shareable
- Freeze on assignment
- Recreate Hash on registration

12d69fc2b3
2025-01-15 04:07:43 +00:00
Takashi Kokubun
5ff1524fde [ruby/erb] Version 4.0.4
b68bfed6a8
2024-01-04 22:34:59 +00:00
Takashi Kokubun
eec7a3f9ee [ruby/erb] Version 4.0.3
c594f2fb86
2023-08-21 21:45:55 -07:00
Josh Nichols
0955ca342e [ruby/erb] Enable frozen_string_literal in all files
(https://github.com/ruby/erb/pull/49)

I was surprised to see erb show up when I was using memory_profiler on
my app. ERB::Compiler#compile has a blank string literal, and it
ended up allocating some 41532 blank strings for a relatively small surface
area.

b7e45c2bdc
2023-08-22 04:41:22 +00:00
Takashi Kokubun
4f8c6711dd [ruby/erb] Version 4.0.2
8c8ff1551b
2022-11-29 04:58:29 +00:00
Takashi Kokubun
129d208f9a [ruby/erb] Fix line numbers after multi-line <%#
(https://github.com/ruby/erb/pull/42)

526885923e
2022-11-29 04:56:03 +00:00
Takashi Kokubun
6fdc677186 [ruby/erb] Version 4.0.1
3bb67009dd
2022-11-27 06:32:58 +00:00
Takashi Kokubun
d2c62426e5 [ruby/erb] Skip using the extension for truffleruby as well
(https://github.com/ruby/erb/pull/39)

* Skip using the extension for truffleruby as well

* Just skip building the C extension for TruffleRuby

* Skip rake compile for truffleruby

* Use resolve_feature_path

* Revert "Use resolve_feature_path"

This reverts commit acc1e0c0ff.

* Use resolve_feature_path with LoadError guard

85dcb08439
2022-11-27 06:30:48 +00:00
Takashi Kokubun
534bac04e7 [ruby/erb] Version 4.0.0
2809a54d88
2022-11-26 06:05:23 +00:00
Takashi Kokubun
574896a0ce [ruby/erb] Define ERB::Escape module
(https://github.com/ruby/erb/pull/38)

Close #32
2022-11-26 05:32:25 +00:00
Takashi Kokubun
addb1cbbfd [ruby/erb] Keep ERB::Util#html_escape private
ERB::Util.html_escape has been public, but ERB::Util#html_escape had
been private.

e62210bf56
2022-11-25 08:54:18 +00:00
Takashi Kokubun
bcdfe12919 [ruby/erb] Allow requiring erb/escape.so alone
(https://github.com/ruby/erb/pull/37)

Prior to this commit, requiring erb/escape first and then requiring erb
did not work as expected.
2022-11-24 23:49:15 +00:00
Takashi Kokubun
8ac4081aa8 [ruby/erb] Split erb.rb into files for each module under ERB
(https://github.com/ruby/erb/pull/36)

f74833cc07
2022-11-24 23:40:53 +00:00
Takashi Kokubun
d6d9b5130e [ruby/erb] Version 3.0.0 2022-10-25 23:14:09 +00:00
Takashi Kokubun
6a352e275b [ruby/erb] Version 2.2.3
03bc4a8274
2021-03-26 12:37:37 +09:00
Takashi Kokubun
724c289b5c [ruby/erb] Version 2.2.2
3d84ea83bc
2021-01-21 15:29:40 +09:00
Takashi Kokubun
e0d92d5e5d [ruby/erb] Version 2.2.1
c8aa019c26
2021-01-21 14:52:20 +09:00
Takashi Kokubun
5f7df72b56
[ruby/erb] Unify ERB version definitions
5df06b8473
2021-01-20 21:43:05 -08:00