Skip to content

Dynamic String/Symbol/Regexp create too much garbage #301

Closed
headius opened this Issue Sep 17, 2012 · 3 comments

1 participant

@headius
JRuby Team member
headius commented Sep 17, 2012

Rails and other libraries frequently use the form :"foo#{bar}" to generate symbols on the fly at runtime. With no caching or improvements, this creates two Ruby Strings, two ByteLists, a Java String and transcoding support classes even when the symbol exists, depending on what "bar" is (if it is not a String, there's a third String and ByteList created for it). I we can get this down to one ByteList total for all cases where bar is a String, Symbol, or Fixnum, which would cover the vast majority of cases.

Currently the interpreter can avoid creating a String for "foo", but that is about as far as it goes. The compiler does not avoid any creation, and every element of the DStr/DSymbol gets lifted all the way up to String before being appended and thrown away.

@headius
JRuby Team member
headius commented Sep 17, 2012

See #300 for additional work needed to make String => Symbol free.

@headius headius added a commit that referenced this issue Sep 17, 2012
@headius headius Improvements for DStr/DSymbol interpretation for #301.
* Special-case core classes in RubyString.append19 to avoid
dyncalls and transient objects.
* Special-case core classes in DNode's EvStr handling to use
append19 directly rather than coercing to a throw-away transient
String.
* Don't create a shared string in DNode, since it's a new ByteList
that's almost immediately written to anyway.
* DSymbol knows super will produce a String, so use more direct
path that doesn't immediately convert to Java String. See #300.
9649428
@headius
JRuby Team member
headius commented Sep 17, 2012

Bulk of compiler work completed in f772683. Work remains in both interpreter and compiler for DSymbol to avoid the intermediate String, but DStr should be greatly improved.

@headius headius closed this Sep 17, 2012
@headius
JRuby Team member
headius commented Sep 18, 2012

DRegexp turned out to be a lot more work, btw, so I filed #302 for it.

@headius headius added a commit that referenced this issue Sep 18, 2012
@headius headius Eliminate transient strings from compiled DSymbol, DXStr logic.
Same general pattern as for DStr. See #301.
9cd88cd
@prathamesh-sonpatki prathamesh-sonpatki pushed a commit to prathamesh-sonpatki/jruby that referenced this issue Sep 18, 2012
@headius headius Improvements for DStr/DSymbol interpretation for #301.
* Special-case core classes in RubyString.append19 to avoid
dyncalls and transient objects.
* Special-case core classes in DNode's EvStr handling to use
append19 directly rather than coercing to a throw-away transient
String.
* Don't create a shared string in DNode, since it's a new ByteList
that's almost immediately written to anyway.
* DSymbol knows super will produce a String, so use more direct
path that doesn't immediately convert to Java String. See #300.
4a5e311
@prathamesh-sonpatki prathamesh-sonpatki pushed a commit to prathamesh-sonpatki/jruby that referenced this issue Sep 18, 2012
@headius headius Eliminate transient strings from compiled DSymbol, DXStr logic.
Same general pattern as for DStr. See #301.
eb59845
@prathamesh-sonpatki prathamesh-sonpatki pushed a commit to prathamesh-sonpatki/jruby that referenced this issue Sep 21, 2012
@headius headius Improvements for DStr/DSymbol interpretation for #301.
* Special-case core classes in RubyString.append19 to avoid
dyncalls and transient objects.
* Special-case core classes in DNode's EvStr handling to use
append19 directly rather than coercing to a throw-away transient
String.
* Don't create a shared string in DNode, since it's a new ByteList
that's almost immediately written to anyway.
* DSymbol knows super will produce a String, so use more direct
path that doesn't immediately convert to Java String. See #300.
186f89a
@prathamesh-sonpatki prathamesh-sonpatki pushed a commit to prathamesh-sonpatki/jruby that referenced this issue Sep 21, 2012
@headius headius Eliminate transient strings from compiled DSymbol, DXStr logic.
Same general pattern as for DStr. See #301.
69dcd6f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.