|
From: | Norbert Nemec |
Subject: | [Texmacs-dev] Revised patch: Speedup in startup time |
Date: | Sun, 14 Jun 2009 16:48:11 +0100 |
User-agent: | Thunderbird 2.0.0.21 (X11/20090409) |
Unfortunately, this adds the overhead of checking a flag at each call, but it is the simplest solution and still significantly faster than the allocation of a new object at each call.
Greetings, Norbert Gubinelli Massimiliano wrote:
Hi all,the patch for is_none (url) does not work correcly. In C++ the order of nonlocal static initializations is undefined, so it can happen (at least to me) that none_tree is not itialized when url_none is called.... This causes a Bus error on mac. Please remove the patch or provide explicit initialization on first use. See for examplehttp://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Runtime_Static_Initialization_Order_IdiomsBest, Max On 14 juin 09, at 03:59, Joris van der Hoeven wrote:Hi Norbert, Thanks for finding this out; I commited your patch. For sure, many more optimizations of this kind can be done, but it also hampers the readability. It is probably a good idea to make more heavy use of symbols; of course the tree_label class already serves this purpose, but is would probably be good to handle frequently used strings in a similar way, for instance following the lines suggested by Max. However, this probably will require quite a lot of work, if we want to make it clean, systematic and really efficient. If profiling could detect the places which are most critical, a few patches of your kind might actually suffice. There is an even more crucial optimization issue, which concerns a systematic use of const references. A long time ago, David Alouche performed some experiences and noticed a 15% speedup just by treating the basics which are now in Kernel. Maybe a 30% or 50% overall speedup could be achieved by using const references in a systematic way. Again, this has to be done very carefully and systematically, which requires quite a lot of time (and hampers readability; C++ is not really nice in this respect). Best wishes, Joris On Fri, Jun 12, 2009 at 02:51:31PM +0200, Norbert Nemec wrote:Hi there,I just tried to do some profiling of TeXmacs and managed to produce a small but significant speedup in the startup time: from 2.0 sec to 1.8 sec (averaged over several runs of "time texmacs -q").Turns out that quite some time was spent in frequent calls to the routine implemented as------- inline bool is_none (url u) { return u->t == tuple ("none"); } -------replacing this by a comparison with a global variable initialized just once. Attached is a tiny patch that implements this change.Far more important than this change itself, however, is the general question that it poses: how many more objects are there in the code that are initialized from a constant string over and over again? How much efficiency could we gain from a global symbol table that is initialized just once?Greetings, Norbert -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01_______________________________________________ Texmacs-dev mailing list address@hidden http://lists.gnu.org/mailman/listinfo/texmacs-dev_______________________________________________ Texmacs-dev mailing list address@hidden http://lists.gnu.org/mailman/listinfo/texmacs-dev_______________________________________________ Texmacs-dev mailing list address@hidden http://lists.gnu.org/mailman/listinfo/texmacs-dev
Optimize url code by using static variables. From: <> --- src/src/System/Classes/url.cpp | 2 -- src/src/System/Classes/url.hpp | 14 ++++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/src/System/Classes/url.cpp b/src/src/System/Classes/url.cpp index 5d95977..8acbceb 100644 --- a/src/src/System/Classes/url.cpp +++ b/src/src/System/Classes/url.cpp @@ -77,8 +77,6 @@ #define URL_SEPARATOR ':' #endif -tree none_tuple= tuple ("none"); - /****************************************************************************** * Unrooted url constructors ******************************************************************************/ diff --git a/src/src/System/Classes/url.hpp b/src/src/System/Classes/url.hpp index 8784e14..cbaf6a0 100644 --- a/src/src/System/Classes/url.hpp +++ b/src/src/System/Classes/url.hpp @@ -49,8 +49,6 @@ inline url as_url(tree t) { return url(t); } * url constructors ******************************************************************************/ -extern tree none_tuple; - url url_general (string name, int type); url url_unix (string name); url url_unix (string dir, string name); @@ -59,9 +57,9 @@ url url_system (string dir, string name); url url_standard (string name); url url_standard (string dir, string name); -inline url url_none () { return as_url (none_tuple); } -inline url url_here () { return as_url (tree (".")); } -inline url url_parent () { return as_url (tree ("..")); } +inline url url_none () { static url u = as_url(tuple("none")) ; return u ; } +inline url url_here () { static url u = as_url(tree(".")); return u ; } +inline url url_parent () { static url u = as_url(tree("..")); return u ; } inline url url_pwd () { return url_system ("$PWD"); } url url_root (string protocol); // root url @@ -80,9 +78,9 @@ inline url url_parent (url u) { return u * url_parent (); } * predicates ******************************************************************************/ -inline bool is_none (url u) { return u->t == none_tuple; } -inline bool is_here (url u) { return u->t == "."; } -inline bool is_parent (url u) { return u->t == ".."; } +inline bool is_none (url u) { static tree t = tuple("none") ; return u->t == t; } +inline bool is_here (url u) { static tree t(".") ; return u->t == t; } +inline bool is_parent (url u) { static tree t(".."); return u->t == t; } inline bool is_atomic (url u) { return is_atomic (u->t); } inline bool is_concat (url u) { return is_tuple (u->t, "concat", 2); } inline bool is_or (url u) { return is_tuple (u->t, "or", 2); }
[Prev in Thread] | Current Thread | [Next in Thread] |