Did you try it without intern'ing? I am wondering if most of this is
from being a fast method or not?
-Tom
On 8/25/07, Charles Oliver Nutter <[EMAIL PROTECTED]> wrote:
> Two changes in attached patch:
>
> - attr accessors should store interned name of variable
> - attr accessor methods can be "fast"
>
> Substantial improvement (this is with the standard ivars hashmap):
>
> BEFORE:
>
> 100k loop of 100 attr accesses and assign to local; one ivar
> 2.695000 0.000000 2.695000 ( 2.695000)
> 2.621000 0.000000 2.621000 ( 2.621000)
> 1.839000 0.000000 1.839000 ( 1.840000)
> 1.836000 0.000000 1.836000 ( 1.836000)
> 1.915000 0.000000 1.915000 ( 1.915000)
>
> AFTER:
>
> 100k loop of 100 attr accesses and assign to local; one ivar
> 1.675000 0.000000 1.675000 ( 1.675000)
> 1.695000 0.000000 1.695000 ( 1.695000)
> 0.905000 0.000000 0.905000 ( 0.905000)
> 0.908000 0.000000 0.908000 ( 0.908000)
> 0.899000 0.000000 0.899000 ( 0.899000)
>
> I would expect similar results from attr setters, but I did not
> benchmark them.
>
> - Charlie
>
> Index: src/org/jruby/RubyModule.java
> ===================================================================
> --- src/org/jruby/RubyModule.java (revision 4182)
> +++ src/org/jruby/RubyModule.java (working copy)
> @@ -1094,11 +1094,11 @@
> attributeScope = Visibility.PRIVATE;
> // FIXME warning
> }
> - final String variableName = "@" + name;
> + final String variableName = ("@" + name).intern();
> final Ruby runtime = getRuntime();
> ThreadContext context = getRuntime().getCurrentContext();
> if (readable) {
> - defineMethod(name, new Callback() {
> + defineFastMethod(name, new Callback() {
> public IRubyObject execute(IRubyObject self, IRubyObject[]
> args, Block block) {
> Arity.checkArgumentCount(getRuntime(), args, 0, 0);
>
> @@ -1115,7 +1115,7 @@
> }
> if (writeable) {
> name = name + "=";
> - defineMethod(name, new Callback() {
> + defineFastMethod(name, new Callback() {
> public IRubyObject execute(IRubyObject self, IRubyObject[]
> args, Block block) {
> // ENEBO: Can anyone get args to be anything but length
> 1?
> Arity.checkArgumentCount(getRuntime(), args, 1, 1);
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
> http://xircles.codehaus.org/manage_email
>
--
Blog: http://www.bloglines.com/blog/ThomasEEnebo
Email: [EMAIL PROTECTED] , [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email