|
Re: Fusion-ifying proto parse trees: msg#00039parsers.spirit.devel
Joel de Guzman wrote: Eric Niebler wrote: I'm not so sure. To flatten A>>B>>C>>D, the following lists must be constructed: cons<A> cons<A,cons<B>> cons<A,cons<B>,cons<C>>> cons<A,cons<B>,cons<C>,cons<D>>> You're pushing stuff to the *end* of a singly-linked list, which is slow, and you end up instantiating lots of mostly unneeded intermediate cons<> types. I count 10 separate instantiations of cons<> here. In other words, this: "return fusion::as_list(join_type(a.elements, b.elements));" from compose.hpp gets more and more expensive as the list grows. When building a proto ET tree, no instantiations are wasted. It gets built by composing sub-trees, like: lit<A> seq<lit<A>,lit<B>> seq<seq<lit<A>,lit<B>>,lit<C>> seq<seq<seq<lit<A>,lit<B>>,lit<C>>,lit<D>> I count only 3 separate instantiations of seq<> and 4 instantiations of lit<> here -- for a total of 7. Three less than eagerly cons-ifying. Oh, wait! I just had a thought. When building a cons<> list as you do, you have to copy the elements from the old list to the new because the list types differ. (In the example above, A is copied 4 times, B 3 times, C twice and D once -- that's 10 copies.) Today, proto makes no fewer copies, but it doesn't have to be that way. seq<> can hold its left and right children by reference! The temporaries won't go out of scope before the expression gets evaluated. And if you're assigning an ET to a rule<>, you can deep-copy (and flatten!) the tree only then. Hmm ... that means going from 10 copies to 0 (assuming that even lit<A> can hold A by reference)! What do you think? Zero-copy expression template construction and segmented iteration over the tree -- I think there's potential there. Regarding your question about taking the minimum result, I lifted this code from John Maddock's regex performance shoot-out. This is how he collects his timing. Yes, this is a black art -- I don't really understand it. Oh, I never suggested segmentation was an algorithmic improvement! Obviously, the computational complexity for visiting every element in a sequence is O(N) no matter how you slice it. The ultimate goal is to make Spirit-2 evaluate fast, while giving Boost a general ET library and allowing Spirit-2, Karma, xpressive and other parsing strategies to play well together. I agree we're not there yet, but I think these results are encouraging. -- Eric Niebler Boost Consulting www.boost-consulting.com ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: Re: Fusion-ifying proto parse trees: 00039, Hartmut Kaiser |
|---|---|
| Next by Date: | Re: Fusion-ifying proto parse trees: 00039, Eric Niebler |
| Previous by Thread: | Re: Fusion-ifying proto parse treesi: 00039, Eric Niebler |
| Next by Thread: | Re: Fusion-ifying proto parse trees: 00039, Joel de Guzman |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |