Skip to content
Tcl Source Code History Of Ticket 3485833
Login

History Of Ticket 3485833

Artifacts Associated With Ticket 3485833

  1. Ticket change [5076918998] (rid 125974) by sebres on 2012-02-08 18:43:04:

    1. assignee initialized to: "dgp"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Hello, 
      
      I've found that by "execution" trace some ensemble commands produce a lot of overhead... 
      without trace it is comparable with not ensemble commands
      i have own profiler (to check which code works slowly), that calls somthing like this :
      
      Tcl_CreateObjTrace( interp, level, TCL_ALLOW_INLINE_COMPILATION | ((TCL_TRACE_ANY_EXEC) >> 2),
               &tclexProfilerTraceProc, inDbgObj, NULL );
      The C procedure "tclexProfilerTraceProc" i have rewritten to test this, that it performs "return TCL_OK;" only.
      
      Strange is the execution times of "string length" and "::tcl::string::length" are not different, 
      but "string range" or "string first" are 100 times slower as its not ensemble commands "::tcl::string::range" or "::tcl::string::first".
      
      That overhead make me not possible, to profile anything code, using ensembles.
      
      Tcl code to be "profiled":
      %%%%
      set s [string repeat A 50000]; puts ok
      puts "--- string range ----"
      puts [time {::tcl::string::range $s 2000 2001} 100000]
      puts [time {::string range $s 2000 2001} 10000]
      puts "--- string first ----"
      puts [time {::tcl::string::first A $s 2000} 100000]
      puts [time {::string first A $s 2000} 10000]
      puts "--- string length ---"
      puts [time {::tcl::string::length $s} 100000]
      puts [time {::string length $s} 10000]
      puts "--- test ------------"
      proc ::test1_string_range {s from to} {set a 5}
      proc ::test2_string_range {ens s from to} {set a 5}
      puts [time {::test1_string_range $s 2000 2001} 10000]
      puts [time {::test2_string_range range $s 2000 2001} 10000]
      %%%%
      
      Result is :
      ok
      --- string range ----
      1.4 microseconds per iteration
      168.8 microseconds per iteration !!!
      --- string first ----
      1.09 microseconds per iteration
      168.8 microseconds per iteration !!!
      --- string length ---
      0.31 microseconds per iteration
      0.0 microseconds per iteration
      --- test ------------
      1.6 microseconds per iteration
      1.5 microseconds per iteration
      
      
    4. foundin initialized to: "obsolete: 8.5.11"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "sebres"
    10. subsystem initialized to: "46. Traces"
    11. title initialized to:
      trace - inexplicable large overhead by ensemble commands
      
    12. type initialized to: "Bug"
  2. Ticket change [559b4c5160] (rid 94168) by sebres on 2012-02-09 01:51:16:

    1. icomment:
      the difference between execution times of "ensemble" and "not ensemble" is then greater if string "s" is longer, and vice versa.
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  3. Ticket change [874d002727] (rid 131671) by dgp on 2012-02-09 02:10:03:

    1. icomment:
      
      Does the 8.5.11 release have this problem,
      or only the tip of the core-8-5-branch ?
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  4. Ticket change [9408b608ac] (rid 105915) by sebres on 2012-02-09 02:28:01:

    1. icomment:
      > Don: original release 8.5.11
      
      What is funny - but even tcl proc is "in trace" faster than "ensemble":
      %
      if {[info command ::org_string] == {}} {
        rename ::string ::org_string
        proc ::string {args} {{*}[lreplace $args 0 0 "::tcl::string::[lindex $args 0]"]}
      }
      .... the same test code ....
      %
      
      The result is :
      ok
      --- string range ----
      2.04 microseconds per iteration
      7.8 microseconds per iteration
      --- string first ----
      1.87 microseconds per iteration
      7.8 microseconds per iteration
      --- string length ---
      0.32 microseconds per iteration
      6.2 microseconds per iteration
      --- test ------------
      3.1 microseconds per iteration
      1.6 microseconds per iteration
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  5. Ticket change [77797cf3ac] (rid 89782) by dgp on 2012-02-09 03:59:44:

    1. icomment:
      
      ok, reverse the question then.  Is the problem
      already corrected on the tip of the core-8-5-branch?
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  6. Ticket change [1aaa2f1844] (rid 123020) by dgp on 2012-02-09 04:00:53:

    1. icomment:
      
      Another releated Q, is it all ensembles
      that have this issue, or only those that
      are byte compiled?
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  7. Ticket change [40931aae0f] (rid 116050) by dgp on 2012-02-09 04:25:03:

    1. assignee changed to: "dkf"
    2. icomment:
      
      The bytecompiled subcommand [string length] is good.
      
      The subcommands that don't compile [string range,first] show
      the problem.
      
      I suspect that every iteration of [time] is re-attempting the
      compile.  No hard evidence yet.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. subsystem changed to: "21. [namespace]"
    6. username: "dgp"
  8. Ticket change [6549cb8cf0] (rid 102516) by dgp on 2012-02-09 04:44:02:

    1. icomment:
      
      Reproduction using just what's in the 
      source distro:
      
      $ make runtest
      ...
      % set s [string repeat A 50000]; puts ok
      ok
      % testcmdtrace resulttest {time {string range $s 2000 2001} 1000}
      171.787 microseconds per iteration
      % testcmdtrace resulttest {time {tcl::string::range $s 2000 2001} 1000}
      2.357 microseconds per iteration
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  9. Ticket change [2a23da4185] (rid 118502) by sebres on 2012-02-09 05:21:52:

    1. icomment:
      > The subcommands that don't compile [string range,first] show
      > the problem.
      But how you explain, that pure tcl proc is faster as "ensemble" by non compiled subcommands? Anything is wrong in ensemble call.
      %
      if {[info command ::org_string] == {}} {
        rename ::string ::org_string
        proc ::string {args} {{*}[lreplace $args 0 0 "::tcl::string::[lindex $args 0]"]}
      }
      .... the same test code ....
      %
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  10. Ticket change [dd308d00d1] (rid 114621) by sebres on 2012-02-09 14:56:20:

    1. icomment:
      by the way, I could not make runtest with windows/MVS 6.0.
      
      ..\generic\tclTest.c(5347) : error C2065: 'intptr_t' : undeclared identifier
      ..\generic\tclTest.c(5347) : error C2146: syntax error : missing ')' before identifier 'Tcl_GetCurrentThread'
      
      my quick workaround :
      
      #if (defined( _MSC_VER ))
      typedef void * intptr_t;
      #endif
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  11. Ticket change [719425383f] (rid 100709) by sebres on 2012-02-09 15:55:39:

    1. icomment:
      No hard evidence, but in debugger by brreakpoint in NsEnsembleImplementationCmd
      it breaks 5 times by "testcmdtrace resulttest {time {string range $s 2000 2001} 5}" 
      and zero times by "testcmdtrace resulttest {time {string length $s} 5}"
      
      Don, you got right: ensemble "string range" will be recompiled each time in "time" body.
      But why "range" only?
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  12. Ticket change [e76915e9ee] (rid 104450) by sebres on 2012-02-09 17:12:43:

    1. icomment:
      Yep, 
      compared to "length", by the "range" it returns in TclCompileEnsemble with TCL_ERROR after checking (... cmdPtr->compileProc == NULL), and go further to recompile in TclCompileScript.
      
      So, either EACH compiled ensemble should implements ALL compiled subcommands also, or in TclCompileEnsemble (or hereafter in TclCompileScript) should be supported a direct call "cmdPtr->objProc" of the subcommand. 
      At least by DONT_COMPILE_CMDS_INLINE or TCL_ALLOW_INLINE_COMPILATION.
      
      I will try to build it later, but each quick solution or workaround are welcome... 
      PS. cause I should as soon as possible complete my profiling :)
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  13. Ticket change [4c975354a6] (rid 126917) by sebres on 2012-02-09 17:25:25:

    1. icomment:
      I noticed something else: why recompile or parse is dependent on length of string "s"?
      It should still parse the token "$s" and not the value of "s". Or I'm way off here? 
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  14. Ticket change [ecf42b45c3] (rid 103799) by dgp on 2012-02-09 22:55:35:

    1. icomment:
      
      Further probing demonstrates the 
      {string range ....} script is getting compiled
      only one time.  It compiles to direct invocation
      of the string command procedure, which is
      NsEnsembleImplementationCmd, because "string"
      is implemented as an ensemble.  This points to
      performance problems there.
      
      A possible alternative would be to have TclCompileEnsemble()
      compile to direct invocation of ::tcl::string::range instead.  To
      go that way would required an examination of the epoch implications,
      since changes in any ensemble dispatch map would then have the
      potential to invalidate bytecode.  (That may already be true).
      
      If we go that way, there may be refactoring opportunities in breaking
      out from TclCompileScript() the central engine that compiles a single
      command so that it could be called by TCE as well.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  15. Ticket change [fa3aebc2e2] (rid 91833) by dkf on 2012-02-09 22:59:41:

    1. icomment:
      Most of cost is due to TEOV_RunEnterTraces, which spends a lot of time converting something to a string.
      
      Timings:
      
      % testcmdtrace resulttest {time {string range $s 2000 2001} 100000}
      590.6396843900001 microseconds per iteration
      % time {string range $s 2000 2001} 100000
      24.18864962 microseconds per iteration
      % time {::tcl::string::range $s 2000 2001} 100000
      12.64128215 microseconds per iteration
      
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  16. Add attachment "sample.txt" [a070891634] (rid 96813) by dkf on 2012-02-09 23:01:23.

  17. Ticket change [b5d609bcd8] (rid 125313) by dkf on 2012-02-09 23:01:23:

    1. icomment:
      
      
      File Added - 435337: sample.txt
      
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  18. Ticket change [cdf4c63bda] (rid 95974) by dkf on 2012-02-09 23:02:54:

    1. icomment:
      I've attached a profiler trace captured while doing a run of the slowest version from my previous comment. ($s is 50k chars)
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  19. Ticket change [ab1a7fa2ee] (rid 101037) by dgp on 2012-02-09 23:25:03:

    1. icomment:
      Ok, that's it.  This oldest style of execution tracing
      wants to have available the command it is tracing
      in string form.  Most of the time this isn't a big demand,
      because the command started in string form, and we just
      have to get to it.
      
      But for ensemble subcommand dispatch, the redirected
      subcommand execution is done by building an objv
      array and directly calling to Tcl_EvalObjv().  When the
      the string version is needed, a list is built and the string
      rep of that list is generated, costing time proportional to
      the total length of all the argument values.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  20. Ticket change [b77df3947a] (rid 125607) by dgp on 2012-02-09 23:33:16:

    1. assignee changed to: "dgp"
    2. icomment:
      
      The usual opinion on this has been that
      when this level of tracing is active, yes
      performance will be harmed.  But if you
      have this level of tracing turned on, we
      assume performance is not the concern,
      but rather some sort of debugging or profiling.  Optimizing
      under these trace conditions hasn't been a priority.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. priority changed to: "3 Low"
    6. subsystem changed to: "46. Traces"
    7. username: "dgp"
  21. Ticket change [7b48d3cfce] (rid 90495) by dgp on 2012-02-10 01:43:22:

    1. icomment:
      The cost of TclScanElement() in dkf's profile
      caught my eye, notably as compared to
      TclConvertElement().  We can't do anything
      about the inherent O(N) nature of the scan,
      but the constant seemed higher than needed.
      
      On the dgp-scan-element branch I have some
      revisions aimed at brining down the constant.
      On the test at issue in this ticket, it knocks about
      half off the tracing cost.  No new test failures.
      Still running tclbench to see if there's some
      countervailing cost somewhere.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  22. Ticket change [28ba8e16e5] (rid 88749) by dgp on 2012-02-10 04:29:33:

    1. icomment:
      
      If the dgp-scan-element branch has significant
      performance pros or cons, they are not clearly 
      demonstrated by tclbench.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  23. Ticket change [cedc5be1d0] (rid 112857) by sebres on 2012-02-10 04:40:06:

    1. icomment:
      the patch is greate...
      > they are not clearly demonstrated by tclbench.
      There are probably large effect on some things such initial compile and loading (source etc).
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  24. Ticket change [f827a2969a] (rid 91491) by dkf on 2012-02-10 05:12:48:

    1. icomment:
      I'm not sure that this is a cost that tclbench is set up to spot; it's largely focussed on bytecode/command costs as they bite most people much harder. Still, this seems to make quite a bit of difference to the speed of ensemble command dispatch with 8.5 (around 40% faster with an --enable-symbols=all build) which is very good, if naively surprising. In a fully optimized build, it makes 17.5% difference when traces are turned on, and seems to be irrelevant without traces.
      
      Make it so.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  25. Ticket change [8e8d55827c] (rid 120127) by sebres on 2012-02-10 18:36:20:

    1. icomment:
      In my tcl fork I have midified a some routines such Tcl_CreateEnsemble, Tcl_SetEnsembleSubcommandList, Tcl_SetEnsembleMappingDict etc.
      
      So after ensemble namespace and subcommands are created, the main ensemle command will be a "dummy" command without compileProc (TclCompileEnsemble), that simple forwards a first arg to corresponding command in ensemble namespace.
      
      I try later to create a patch for core-8-5-11...
      
      My performance now w/o tracing:
      --- string range ----
      0.62 microseconds per iteration
      0.78 microseconds per iteration
      --- string first ----
      0.63 microseconds per iteration
      0.78 microseconds per iteration
      --- string length ---
      0.31 microseconds per iteration
      0.16 microseconds per iteration
      
      Performance with tracing:
      --- string range ----
      2.16 microseconds per iteration
      2.8 microseconds per iteration
      --- string first ----
      1.78 microseconds per iteration
      1.8 microseconds per iteration
      --- string length ---
      0.32 microseconds per iteration
      0.32 microseconds per iteration
      
      By tclbench it seems to be equal.
      But strange is, that some my own test scripts running up to one-fifth faster as earlier.
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  26. Ticket change [319a77ffaa] (rid 93453) by sebres on 2012-02-10 22:38:41:

    1. icomment:
      
      
      File Added - 435424: traceEnsembleOverhead.patch
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  27. Add attachment "traceEnsembleOverhead.patch" [fd3939e067] (rid 108378) by sebres on 2012-02-10 22:38:41.

  28. Ticket change [f63b1c8978] (rid 130265) by sebres on 2012-02-10 22:45:52:

    1. icomment:
      dgp:
      > When the the string version is needed, a list is built and 
      > the string rep of that list is generated, costing time 
      > proportional to the total length of all the argument values
      
      Thanks for your reference Don, you got right.
      
      I have found another (bether) solution as my workaround before.
      I use TclGetSrcInfoForCmd, but with "-2", 
      to shift string pointer from "string range ..." to "range ..."
      
      I've fixed it for 8.5.11 (org) and my fork. It work correct, but some tests still running.
      
      Patch is attached now.
      Your reviews are welcome.
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. resolution changed to: "Fixed"
    5. username: "sebres"
  29. Add attachment "traceEnsembleOverhead2.patch" [d21288ef8e] (rid 113465) by sebres on 2012-02-10 23:02:44.

  30. Ticket change [0da3365014] (rid 114399) by sebres on 2012-02-10 23:02:44:

    1. icomment:
      
      
      File Added - 435425: traceEnsembleOverhead2.patch
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  31. Ticket change [73b400f159] (rid 105084) by sebres on 2012-02-10 23:36:54:

    1. icomment:
      not yet really safe - within trace using itcl3.4 tests I have access violation (at TclGetSrcInfoForPc+0x14C). without trace ok.
      I will search and fix it later.
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  32. Ticket change [a37e31832b] (rid 110054) by sebres on 2012-02-13 23:17:41:

    1. icomment:
      The last mentioned exception in itcl3.4 is recently occured within execution trace with 8.5.11 (original) also. Therewith it is another bug (possible anywhere in itcl) - not yet found. It's very hardly to reproduce, cause occured sporadical only by initializing (within source in new thread).
      
      For this reason, the solution is fine for me.
      Patch with tiny changes attached.
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  33. Add attachment "traceEnsembleOverhead3.patch" [edb2107392] (rid 103936) by sebres on 2012-02-13 23:18:07.

  34. Ticket change [b463e91210] (rid 125027) by sebres on 2012-02-13 23:18:08:

    1. icomment:
      
      
      File Added - 435716: traceEnsembleOverhead3.patch
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  35. Ticket change [878a8cf192] (rid 131712) by dgp on 2012-02-14 00:58:44:

    1. icomment:
      
      Some bug in this Tracker is preventing my download
      of the attachments.  If you could please commit the
      patches to some branch of the fossil repos, that would
      be a good way to get it to reviewers.  Thanks!
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  36. Ticket change [2f9eba1a23] (rid 93086) by sebres on 2012-02-14 20:09:40:

    1. icomment:
      4 Don:
      
      i have checked into your leaf "dgp-scan-element" :
      http://core.tcl.tk/tcl/info/d6c4824b30
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  37. Ticket change [48c89ed084] (rid 99956) by dgp on 2012-02-14 20:30:22:

    1. icomment:
      
      Thanks, I see it.  Hope to have time on Thursday to
      take a good look.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  38. Ticket change [d0b5e9d019] (rid 113226) by dgp on 2012-03-06 01:15:21:

    1. icomment:
      Sadly, the dgp-scan-element branch now holds
      at least three different, separable changes, that
      really ought to receive independent review. IMHO.
      
      1) Speedup of TclScanElement() that strangely doesn't
          appear to speed things up very much except in this
          particular demo.
      
      2) The alternative kludge to solve/avoid the problem
           originally reported.
      
      3) Some apparent portability issues in the "registry"
          and "dde" packages.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  39. Ticket change [5d6aac97fc] (rid 115456) by dgp on 2012-03-06 01:44:30:

    1. icomment:
      See ticket 3497099 for continued work on item 3).
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  40. Ticket change [119768211f] (rid 95171) by dgp on 2012-03-06 02:12:25:

    1. icomment:
      Branch bug-3485833 opened to track item 2)
      independently.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  41. Ticket change [90353f11d0] (rid 120410) by sebres on 2012-03-06 16:38:39:

    1. icomment:
      3) commited in "dgp-scan-element"
      http://core.tcl.tk/tcl/info/a16a2b5417
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  42. Ticket change [63a3b57951] (rid 92616) by dgp on 2012-03-06 22:31:57:

    1. icomment:
      I don't understand the purpose in the patched
      TclGetSrcInfoFroCmd() of moving the "command"
      pointer forward off of "string" and onto "range" in
      the comment example "string range".
      
      If we've already located a pointer to "string range"
      seems to me that's the traced command and we can
      just use it without modification.  If there's no need for
      modification, then there's no need for a special sentinel
      value to trigger the modification, and things can get much
      simpler.
      
      If there's really a need for this, I need it explained to me, and
      we should probably add a test demonstrating it.  We'll also
      have to fix the code so it works better.  It's not correct to just
      assume that each word in a Tcl command is separated from
      the next word by a single space.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  43. Ticket change [56e79151f0] (rid 94405) by sebres on 2012-03-07 01:19:19:

    1. icomment:
      By following code :
      proc ::A::test {} {
        string range Test 0 4
      }
      
      we should have a following "call stack" by tracing:
      
      ::tcl::string::RANGE
      string
      ::A::test
      
      without shift from "string range" to "range" we have following "call stack" :
      
      ::tcl::string::STRING
      string
      ::A::test
      
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  44. Ticket change [7de33e4022] (rid 97303) by dgp on 2012-03-07 01:31:29:

    1. icomment:
      
      I don't follow.  Do you have a test case we
      can add to the test suite that would demo the
      difference?
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  45. Ticket change [92b23a58df] (rid 120814) by sebres on 2012-03-07 06:41:36:

    1. icomment:
      I have it unfortunately in C as part of my tcl profiler (very large + custom tcl),
      but in pure TCL it is something like this (I do not know whether all interp trace flags are the same):
      
      % proc test {} {string range {} 0 0}
      % trace add execution test enterstep {put_stack}
      % proc put_stack {args} {puts [join $args " - "]}
      % test
      string range {} 0 0 - enterstep
      ::tcl::string::range {} 0 0 - enterstep
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  46. Ticket change [507d05f851] (rid 125980) by sebres on 2012-03-07 16:00:51:

    1. icomment:
      I have tested it with (-1) insted of ENSEMBLE_PSEUDO_COMMAND - the output is the same. 
      This happens because TraceExecutionProc gets the command from objv[0] and that is "::tcl::string::range". 
      
      I am not sure, perhaps we can use the "simple" variant that you have suggested - without ENSEMBLE_PSEUDO_COMMAND. 
      I will test it with my profiler - I have therein a strange piece of code, that build calling command name from current namespace and "char * command", when objv[0] is NULL or objc = 0. 
      It may be obsolete (since 8.4 or 8.5).
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  47. Ticket change [07277a83f1] (rid 89337) by sebres on 2012-03-07 22:43:32:

    1. icomment:
      Experimental trying to use TclGetSrcInfoForCmd without special sentinel ENSEMBLE_PSEUDO_COMMAND (as suggested from Don) 
      commited in bug-3485833.
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  48. Ticket change [1e3fd1839e] (rid 150989) by sebres on 2017-01-04 14:25:01:

    1. closer changed to: "nobody"
    2. comment changed to:
      Hello, 
      
      I've found that by "execution" trace some ensemble commands produce a lot of overhead... 
      without trace it is comparable with not ensemble commands
      i have own profiler (to check which code works slowly), that calls somthing like this :
      
      Tcl_CreateObjTrace( interp, level, TCL_ALLOW_INLINE_COMPILATION | ((TCL_TRACE_ANY_EXEC) >> 2),
               &tclexProfilerTraceProc, inDbgObj, NULL );
      The C procedure "tclexProfilerTraceProc" i have rewritten to test this, that it performs "return TCL_OK;" only.
      
      Strange is the execution times of "string length" and "::tcl::string::length" are not different, 
      but "string range" or "string first" are 100 times slower as its not ensemble commands "::tcl::string::range" or "::tcl::string::first".
      
      That overhead make me not possible, to profile anything code, using ensembles.
      
      Tcl code to be "profiled":
      %%%%
      set s [string repeat A 50000]; puts ok
      puts "--- string range ----"
      puts [time {::tcl::string::range $s 2000 2001} 100000]
      puts [time {::string range $s 2000 2001} 10000]
      puts "--- string first ----"
      puts [time {::tcl::string::first A $s 2000} 100000]
      puts [time {::string first A $s 2000} 10000]
      puts "--- string length ---"
      puts [time {::tcl::string::length $s} 100000]
      puts [time {::string length $s} 10000]
      puts "--- test ------------"
      proc ::test1_string_range {s from to} {set a 5}
      proc ::test2_string_range {ens s from to} {set a 5}
      puts [time {::test1_string_range $s 2000 2001} 10000]
      puts [time {::test2_string_range range $s 2000 2001} 10000]
      %%%%
      
      Result is :
      ok
      --- string range ----
      1.4 microseconds per iteration
      168.8 microseconds per iteration !!!
      --- string first ----
      1.09 microseconds per iteration
      168.8 microseconds per iteration !!!
      --- string length ---
      0.31 microseconds per iteration
      0.0 microseconds per iteration
      --- test ------------
      1.6 microseconds per iteration
      1.5 microseconds per iteration
      
    3. icomment:
      Interim status of subject:
      
      Even without any tracing, current trunk have still very large overhead, that concerns to ensemble handling (by the way, greater than in 8.5). 
      It could be better explained using my new command "timerate" (fairly more precise by measurement as the "time"), currently available for trunk-based branches in https://github.com/sebres/tcl/pull/3
      
      Following example will provide you insight about ensemble-overhead (compiled as well as non-compiled execution takes by ensemble 70% more time):
      
      ```
      % set s [string repeat A 50000]; puts ok
      ok
      % # calibrate to minimize influence of measurement overhead (and byte code execution overhead):
      
      % timerate -calibrate {}
      0.04537374883248807 µs/#-overhead, 0.045506 µs/#, 42895062 #, 21974929 #/sec
      
      % # test compiled execution:
      % timerate {string first A $s 2000}
      0.321560 µs/#, 2725287 #, 3109837 #/sec
      % timerate {::tcl::string::first A $s 2000}
      0.191541 µs/#, 4220926 #, 5220810 #/sec
      
      % # calibrate again (slower, non-compiled direct execution via TclEvalObjEx):
      % timerate -direct -calibrate {}
      0.07950384713110215 µs/#-overhead, 0.080109 µs/#, 24366669 #, 12482924 #/sec
      
      % timerate -direct {string first A $s 2000}
      0.313794 µs/#, 2542604 #, 3186803 #/sec
      % timerate -direct {::tcl::string::first A $s 2000}
      0.190985 µs/#, 3697004 #, 5236000 #/sec
      ```
      
    4. login: "sebres"
    5. mimetype: "text/plain"
    6. severity changed to: "Minor"