Status: New
Owner: ----
Labels: Type-Bug Priority-Medium

New issue 1212 by [email protected]: Speedup invocation of methods on primitive string values.
http://code.google.com/p/v8/issues/detail?id=1212

String.prototype.a = function () { };

var N = 1e7;

function foo () {
    var a = "a";
    String.prototype.a = function () { };
    for (var i = 0; i < N; i++) {
        a.a();
    }
}

function bar () {
    var a = "a";
    for (var i = 0; i < N; i++) {
        new String(a).a();
    }
}

function baz () {
    var a = new String("a");
    for (var i = 0; i < N; i++) {
        a.a();
    }
}

function m (f) {
    var s = Date.now();
    f();
    print(Date.now() - s);
}

m(foo);
m(bar);
m(baz);

$ ./shell test-string.js
19750
175
89

100x times difference is unexpected.

There two major problems here:
1) we do not have specialized IC for calls that require coercion to object so we constantly go to the runtime system. 2) something strange happened with GC: V8 is constantly hitting mark-sweep (while it should be scavenging, and it was before I updated my clean checkout to the bleeding_edge HEAD).

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to