#19810: Optimize get_key() for cached functions
-------------------------------------+-------------------------------------
       Reporter:  jdemeyer           |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-7.0
      Component:  misc               |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Jeroen Demeyer     |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/jdemeyer/ticket/19810            |  9e41b4cc969b56768d5492cfd82f0a74b3afb829
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Old description:

> The code to determine the actual key from `*args` and `**kwds` for cached
> functions is duplicated (even with slightly different implementations!)
> in many methods. There is also a lot of indirection.
>
> We add a new Cython method `get_key_args_kwds()` to solve this problem
> and do a lot of optimizations.

New description:

 The code to determine the actual key from `*args` and `**kwds` for cached
 functions is duplicated (even with slightly different implementations!) in
 many methods. There is also a lot of indirection.

 We add a new Cython method `get_key_args_kwds()` to solve this problem and
 do a lot of optimizations.

 '''Before''':
 {{{
 sage: def f(x): return x
 sage: cf = cached_function(f)
 sage: timeit('cf(1)', number=10^6, repeat=100)
 1000000 loops, best of 100: 395 ns per loop
 }}}

 '''After''':
 {{{
 sage: def f(x): return x
 sage: cf = cached_function(f)
 sage: timeit('cf(1)', number=10^6, repeat=100)
 1000000 loops, best of 100: 348 ns per loop
 }}}

--

Comment (by jdemeyer):

 The speed gain is about 12% for a function with 1 argument.

--
Ticket URL: <http://trac.sagemath.org/ticket/19810#comment:11>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to