Hi Sébastien!
On Sun, Apr 11, 2010 at 12:18:42AM +0200, Sébastien Labbé wrote:
> I am currently working on a patch in sage-combinat tree which make use
> of dynamic classes [1]. Indeed, in sage/combinat/words, dynamic
> classes would be more than welcomed as the number of classes get huge
> quickly because of mutiple datatypes (list, tuple, str, callable,
> iterable, with caching or not), multiple math object (finite, infinite
> or unknown) and even multiple geometric representations (word path on
> the square grid, etc.). I was able to use dynamic classes and it work
> well. I get All Test passed. But what about timings :
>
> sage -t finite_word.py goes from 15.8s to 19.3s.
>
> the creation of a single word from a list range(10) is multiplied by
> two in time.
>
> I must admit that not everything is optimized as I know it could. For
> example, each time a word is created, its class is reconstructed from
> scratch as well. Maybe some caching could be done or lazy
> attributes... But I really wonder if it will be possible to get as
> fast as it was before...
>
> Do anybody of you already used dynamic classes?
Well, most (non Cython) Sage objects now use dynamic class under the
hood :-) Look for dynamic_class in:
sage/categories/sets_cat.py
sage/structure/parent.pyx
> Do anybody of you already tried to optimize its use to get as fast
> as dozens of hardcoded classes? Is there a file in Sage that make
> use of dynamic classes that I could inspire myself from? Should I
> continue to try to work on this optimization?
dynamic_class already has a cache. It uses @cached_function though,
which, as has been discussed recently on sage-devel, is currently dog
slow.
In our case, this has not yet been an issue, since:
- on one hand we don't create that many parents, so the dynamic class
call in parent.pyx is negligible
- on the other hand, the element_class for elements (see sets_cat) is
constructed once for all by the parent.
So I see three (cumulative?) options for you:
- Participate to the efforts to make cached_function blazingly fast
as it ought to be (you will be a hero)
- Make the dynamic_class function faster by Cythoning it
- Do your own caching "en amont" if there is a natural place for it
(like is the case for the default behavior for parents / elements).
Good luck!
Nicolas
--
Nicolas M. Thiéry "Isil"
http://Nicolas.Thiery.name/
--
You received this message because you are subscribed to the Google Groups
"sage-combinat-devel" group.
To post to this group, send email to sage-combinat-de...@googlegroups.com.
To unsubscribe from this group, send email to
sage-combinat-devel+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sage-combinat-devel?hl=en.