Leopold Toetsch <[EMAIL PROTECTED]> wrote:

> OTOH I'm thinking of adding _keyed_str variants to used _keyed vtables.
> We are already constructing too much temporary key PMCs from a string
> just to pass a string to an hash lookup. Object ops and functions do
> this all over the place repeatedly.

And here is a profile timing comparison for doing 1E6 findclass ops [1]:

 CODE  OP FULL NAME            CALLS  TOTAL TIME   AVG T. ms
 ----  -----------------     -------  ----------  ----------
  743  findclass_i_sc        1000000    1.356876      0.0014
   -3  DOD                      1058    0.211712      0.2001
...
 ----  -----------------     -------  ----------  ----------
   11                        3001066    1.666512      0.0006

Doing the same with a direct hash_get() [2]:

 1257  findclass_str_i_sc    1000000    0.462577      0.0005
...
 ----  -----------------     -------  ----------  ----------
   11                        3000009    0.564461      0.0002

This is 3 times faster and saves ~1000 DOD runs.


[1]
    newclass P1, "Foo"
    loadlib P2, "myops_ops"

    set I0, 1000000
    time N0
loop:
    findclass I1, "Foo"  # or findclass_str in myops.ops
    dec I0
    if I0, loop
    time N1
    sub N1, N0
    print N1
    print "\n"
    end

unoptimized build, Athlon 800.

[2] Of course calling hash_get() directly isn't the way to go, but
VTABLE_exists_keyed_str() is just one vtable call slower, which isn't
much.

# from dynoplibs/myops.ops
# make -C dynoblibs clean all

inline op findclass_str(out INT, in STR) {
  Hash *h = (Hash*)PMC_ptr1v(interpreter->class_hash);
  if (hash_get(interpreter, h, $2)) {
    $1 = 1;
  } else {
    $1 = 0;
  }
  goto NEXT();
}

leo

Reply via email to