Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating temporary objects in read_irep_record_1() #4920

Closed
wants to merge 1 commit into from

Conversation

dearblue
Copy link
Contributor

@dearblue dearblue commented Jan 4, 2020

Since the irep pool element is now NUL terminated, break compatibility for mruby binary format.

Since the irep pool element is now NUL terminated, break compatibility
for mruby binary format.
@matz
Copy link
Member

matz commented Jan 4, 2020

I like the idea, but I worry about the compatibility issue. Let me investigate the idea for a while.

@shuujii
Copy link
Contributor

shuujii commented Jan 4, 2020

Null termination seems necessary for mrb_cstr_to_dbl to request it.

In most cases, if null termination is performed on the area allocated by MRB_ALLOCV (#4853), it can be realized without heap allocation or object creation, I think.

Alternatively, we may be able to use mrb_str_to_dbl with the following treatments:

  1. Perform null termination using MRB_ALLOCV instead of RSTRING_CSTR in mrb_str_to_dbl.
  2. Introduce something like CRuby's fake string (using RString on the stack).

FYI, there is the following bug (unreported). I think this can be fixed via 1.

$ ruby -e 'p "1\x002".to_f'
1.0
$ mruby -e 'p "1\x002".to_f'
trace (most recent call last):
-e:1: string contains null byte (ArgumentError)

@dearblue
Copy link
Contributor Author

dearblue commented Jan 5, 2020

Here are some things I want to appeal to in this proposal:

  1. Work object creation is reduced (= GC is reduced).
  2. Reduced transfer between memories.
  3. String literals are already NUL-terminated and can be extracted as C strings.

(1) and (2) can be especially effective on slow devices because they affect irep read time.
It's now that I came up with (3). 😸

@matz matz closed this in 111045e Jan 6, 2020
matz added a commit that referenced this pull request Jan 6, 2020
@matz
Copy link
Member

matz commented Jan 6, 2020

111045e is my attempt to address this issue that:

  • Avoid creating temporary strings
  • Do not change the binary format
  • "1\x002".to_f works OK
  • Float("0x10") now works

@dearblue
Copy link
Contributor Author

dearblue commented Jan 6, 2020

I think it is a good change. Thank you!

@dearblue dearblue deleted the tempobj branch January 6, 2020 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants