ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120367] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference
@ 2024-12-22 17:00 zverok (Victor Shepelev) via ruby-core
  2024-12-23  9:41 ` [ruby-core:120376] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zverok (Victor Shepelev) via ruby-core @ 2024-12-22 17:00 UTC (permalink / raw)
  To: ruby-core; +Cc: zverok (Victor Shepelev)

Issue #20978 has been reported by zverok (Victor Shepelev).

----------------------------------------
Bug #20978: Ractor[]/Thread[]/Fiber[] behavior difference
https://bugs.ruby-lang.org/issues/20978

* Author: zverok (Victor Shepelev)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-12-22T06:08:19Z master 3808d29e20) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
`Ractor.[]` and `.[]=` support string and symbol keys (treating them by string value, and also accepting anything responding to `#to_str`):

```ruby
Ractor[:value] = 10
Ractor[:value] #=> 10
Ractor['value'] #=> 10
o = Object.new
def o.to_str = 'value'
Ractor[o] #=> 10

Ractor[1]
# in 'Ractor.[]': 1 is not a symbol nor a string (TypeError)
```

But `Fiber.[]` only accept symbols:
```ruby
Fiber[:value] = 10
Fiber['value']
# in 'Fiber.[]': wrong argument type String (expected Symbol) (TypeError)
```

`Thread#[]` and `#[]=` behave like Ractor’s. 

(The documentation for Fiber and Thread follows the reality—while Ractor’s current docs don’t specify key type at all—but the discrepancy feels somewhat weird.)



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:120376] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference
  2024-12-22 17:00 [ruby-core:120367] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference zverok (Victor Shepelev) via ruby-core
@ 2024-12-23  9:41 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-12-23 11:01 ` [ruby-core:120377] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-12-23  9:41 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20978 has been updated by nobu (Nobuyoshi Nakada).


https://github.com/ruby/ruby/pull/12438

----------------------------------------
Bug #20978: Ractor[]/Thread[]/Fiber[] behavior difference
https://bugs.ruby-lang.org/issues/20978#change-111153

* Author: zverok (Victor Shepelev)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-12-22T06:08:19Z master 3808d29e20) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
`Ractor.[]` and `.[]=` support string and symbol keys (treating them by string value, and also accepting anything responding to `#to_str`):

```ruby
Ractor[:value] = 10
Ractor[:value] #=> 10
Ractor['value'] #=> 10
o = Object.new
def o.to_str = 'value'
Ractor[o] #=> 10

Ractor[1]
# in 'Ractor.[]': 1 is not a symbol nor a string (TypeError)
```

But `Fiber.[]` only accept symbols:
```ruby
Fiber[:value] = 10
Fiber['value']
# in 'Fiber.[]': wrong argument type String (expected Symbol) (TypeError)
```

`Thread#[]` and `#[]=` behave like Ractor’s. 

(The documentation for Fiber and Thread follows the reality—while Ractor’s current docs don’t specify key type at all—but the discrepancy feels somewhat weird.)



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:120377] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference
  2024-12-22 17:00 [ruby-core:120367] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference zverok (Victor Shepelev) via ruby-core
  2024-12-23  9:41 ` [ruby-core:120376] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-12-23 11:01 ` nobu (Nobuyoshi Nakada) via ruby-core
  2025-01-07 14:28 ` [ruby-core:120523] " Eregon (Benoit Daloze) via ruby-core
  2025-01-07 14:44 ` [ruby-core:120525] " zverok (Victor Shepelev) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-12-23 11:01 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #20978 has been updated by nobu (Nobuyoshi Nakada).


Before commit:d4c720a91bc7bb9ff31810e1720acffb939f7a2f, fiber storage used `rb_check_id` to check arguments.
This function tries to convert a non-Symbol value to a String.
So this bug is a regression, I think.

----------------------------------------
Bug #20978: Ractor[]/Thread[]/Fiber[] behavior difference
https://bugs.ruby-lang.org/issues/20978#change-111154

* Author: zverok (Victor Shepelev)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-12-22T06:08:19Z master 3808d29e20) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
`Ractor.[]` and `.[]=` support string and symbol keys (treating them by string value, and also accepting anything responding to `#to_str`):

```ruby
Ractor[:value] = 10
Ractor[:value] #=> 10
Ractor['value'] #=> 10
o = Object.new
def o.to_str = 'value'
Ractor[o] #=> 10

Ractor[1]
# in 'Ractor.[]': 1 is not a symbol nor a string (TypeError)
```

But `Fiber.[]` only accept symbols:
```ruby
Fiber[:value] = 10
Fiber['value']
# in 'Fiber.[]': wrong argument type String (expected Symbol) (TypeError)
```

`Thread#[]` and `#[]=` behave like Ractor’s. 

(The documentation for Fiber and Thread follows the reality—while Ractor’s current docs don’t specify key type at all—but the discrepancy feels somewhat weird.)



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:120523] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference
  2024-12-22 17:00 [ruby-core:120367] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference zverok (Victor Shepelev) via ruby-core
  2024-12-23  9:41 ` [ruby-core:120376] " nobu (Nobuyoshi Nakada) via ruby-core
  2024-12-23 11:01 ` [ruby-core:120377] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2025-01-07 14:28 ` Eregon (Benoit Daloze) via ruby-core
  2025-01-07 14:44 ` [ruby-core:120525] " zverok (Victor Shepelev) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2025-01-07 14:28 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #20978 has been updated by Eregon (Benoit Daloze).


IIRC it was actually intentional to only allow symbols, as this makes it much more feasible to e.g. represent Fiber storage as object shapes.
This was discussed on the ticket adding Fiber storage.

Strings are not always interned, and interning them is a non-trivial cost.
And when not interned there is a non-trivial overhead to compare them, making every access slower.
At least the current code seems to intern (`rb_to_symbol()`), so using Strings is just slower but doesn't slow down every Fiber storage access.

Why would anyone want to use strings for this API, if it's going to be converted to Symbol internally anyway and so slower than using the Symbol?

----------------------------------------
Bug #20978: Ractor[]/Thread[]/Fiber[] behavior difference
https://bugs.ruby-lang.org/issues/20978#change-111328

* Author: zverok (Victor Shepelev)
* Status: Closed
* ruby -v: ruby 3.4.0dev (2024-12-22T06:08:19Z master 3808d29e20) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
`Ractor.[]` and `.[]=` support string and symbol keys (treating them by string value, and also accepting anything responding to `#to_str`):

```ruby
Ractor[:value] = 10
Ractor[:value] #=> 10
Ractor['value'] #=> 10
o = Object.new
def o.to_str = 'value'
Ractor[o] #=> 10

Ractor[1]
# in 'Ractor.[]': 1 is not a symbol nor a string (TypeError)
```

But `Fiber.[]` only accept symbols:
```ruby
Fiber[:value] = 10
Fiber['value']
# in 'Fiber.[]': wrong argument type String (expected Symbol) (TypeError)
```

`Thread#[]` and `#[]=` behave like Ractor’s. 

(The documentation for Fiber and Thread follows the reality—while Ractor’s current docs don’t specify key type at all—but the discrepancy feels somewhat weird.)



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:120525] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference
  2024-12-22 17:00 [ruby-core:120367] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference zverok (Victor Shepelev) via ruby-core
                   ` (2 preceding siblings ...)
  2025-01-07 14:28 ` [ruby-core:120523] " Eregon (Benoit Daloze) via ruby-core
@ 2025-01-07 14:44 ` zverok (Victor Shepelev) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: zverok (Victor Shepelev) via ruby-core @ 2025-01-07 14:44 UTC (permalink / raw)
  To: ruby-core; +Cc: zverok (Victor Shepelev)

Issue #20978 has been updated by zverok (Victor Shepelev).


> Why would anyone want to use strings for this API, if it's going to be converted to Symbol internally anyway and so slower than using the Symbol?

TBH, I’d, too, rather expect only Symbols to work for such “system programming” (so to say) APIs. I just raised a concern about the inconsistency of similar APIs here.

----------------------------------------
Bug #20978: Ractor[]/Thread[]/Fiber[] behavior difference
https://bugs.ruby-lang.org/issues/20978#change-111329

* Author: zverok (Victor Shepelev)
* Status: Closed
* ruby -v: ruby 3.4.0dev (2024-12-22T06:08:19Z master 3808d29e20) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
`Ractor.[]` and `.[]=` support string and symbol keys (treating them by string value, and also accepting anything responding to `#to_str`):

```ruby
Ractor[:value] = 10
Ractor[:value] #=> 10
Ractor['value'] #=> 10
o = Object.new
def o.to_str = 'value'
Ractor[o] #=> 10

Ractor[1]
# in 'Ractor.[]': 1 is not a symbol nor a string (TypeError)
```

But `Fiber.[]` only accept symbols:
```ruby
Fiber[:value] = 10
Fiber['value']
# in 'Fiber.[]': wrong argument type String (expected Symbol) (TypeError)
```

`Thread#[]` and `#[]=` behave like Ractor’s. 

(The documentation for Fiber and Thread follows the reality—while Ractor’s current docs don’t specify key type at all—but the discrepancy feels somewhat weird.)



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-01-07 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-22 17:00 [ruby-core:120367] [Ruby master Bug#20978] Ractor[]/Thread[]/Fiber[] behavior difference zverok (Victor Shepelev) via ruby-core
2024-12-23  9:41 ` [ruby-core:120376] " nobu (Nobuyoshi Nakada) via ruby-core
2024-12-23 11:01 ` [ruby-core:120377] " nobu (Nobuyoshi Nakada) via ruby-core
2025-01-07 14:28 ` [ruby-core:120523] " Eregon (Benoit Daloze) via ruby-core
2025-01-07 14:44 ` [ruby-core:120525] " zverok (Victor Shepelev) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).