Skip to content
Tcl Source Code History Of Ticket f05f5ef759
Login

History Of Ticket f05f5ef759

Artifacts Associated With Ticket f05f5ef759

  1. Ticket change [d1ce0f2783] (rid 227578) by sebres on 2024-06-11 23:59:30:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      In an attempt to fix the bottleneck, I found that command <code>lseq</code> is a bit raw and has several bugs and inconsistencies.
      
      1. Duplicative evaluation of expressions, what not only inefficient, but also buggy and hardly deterministic (if someone makes storable operations inside, like <code>incr</code>). So every expression will be invoked twice, however, still worse, the value may be thereby from the first or the second eval depending on its result type (by int wins 1st eval, by double wins the 2nd eval).
      For example (red - current state, green - expected)
      <code><pre style="padding-left:2rem;">
        % set i 0; list [lseq {[puts "just a trace, i:$i"; incr i]-1} {[incr i]}] i:$i
        just a trace, i:0
      <b style="color:red;">- just a trace, i:1</b>
      <b style="color:red;">- {0 1 2 3} i:4</b>
      <b style="color:green;">+ {0 1 2} i:2</b>
      &nbsp;
        % set i 0; list [lseq {[puts "just a trace, i:$i"; incr i]-1} {[incr i]+0.1}] i:$i
        just a trace, i:0
      <b style="color:red;">- just a trace, i:1</b>
      <b style="color:red;">- {0.0 1.0 2.0 3.0 4.0} i:4</b>
      <b style="color:green;">+ {0.0 1.0 2.0} i:2</b>
      </pre></code>
      
      2. Usage of lseq-operators has a bottleneck by saving the result and attempt to eval it as expression (due to wrong order of checks). What causes almost 40x  -50x growth of the execution time per operator. For example:
      <code><pre style="padding-left:2rem;">
      % timerate {lseq 1 10}
      <span style="color:green;">0.237085 µs/# 3588607 # 4217895 #/sec 850.805 net-ms</span>
      % timerate {lseq 1 to 10}
      <span style="color:red;">9.000940 µs/# 110589 # 111099 #/sec 995.405 net-ms</span>
      % timerate {lseq 1 10 2}
      <span style="color:green;">0.248337 µs/# 3458008 # 4026792 #/sec 858.750 net-ms</span>
      % timerate {lseq 1 to 10 by 2}
      <span style="color:red;">18.5890 µs/# 53678 # 53795.4 #/sec 997.818 net-ms</span>
      </pre></code>
      
      3. Inconsistent handing by double (round-able to integer doubles sometimes causes integer series, sometimes double series and sometimes, mostly by count, an error '<code>expected integer but got "3.0"</code>' (for example for <code>lseq 3.0</code>)
      
      4. A series with few elements but big-integers can cause a max list length error. Either it'd need different error message, or it must be fixed for big-ints (support them). For example 3 elements series:
      <code><pre style="padding-left:2rem;">
      % lseq 0x[string repeat f 14]0 .. 0x[string repeat f 14]2
      1152921504606846960 1152921504606846961 1152921504606846962
      % lseq 0x[string repeat f 15]0 .. 0x[string repeat f 15]2
      <span style="color:red;">max length of a Tcl list exceeded</span>
      </pre></code>
      
      5. If lseq supports expressions, it must do that properly. For instance I expect the same error here (and definitely not "bad operation" in the 2nd case):
      <code><pre style="padding-left:2rem;">
      % lseq [expr {$i/0}]
      divide by zero
      % lseq {$i/0}
      <span style="color:red;">bad operation "$i/0": must be .., to, count, or by</span>
      </pre></code>
      
      6. During my performance tests I saw some leaks... no idea exactly where and don't intend to invest the time here, because as I was ready with my code review I cannot reproduce the leaks anymore.
      
    5. foundin initialized to: "8.7+"
    6. is_private initialized to: "0"
    7. login: "sebres"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "50e9528765c18296566374b3fde2df942c394efd"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "sebres"
    14. subsystem initialized to: "17. Commands I-L"
    15. title initialized to:
      lseq - duplicative expr eval, bottleneck by usage of operators, inconstistent handling of indices (int vs. double vs. error), etc
      
    16. type initialized to: "Bug"
  2. Ticket change [c8e70f8fcd] (rid 227586) by sebres on 2024-06-12 00:22:17:

    1. icomment:
      4 of the issues (1-3 and 6) are fixed now in 8.7/9.0.<br/>
      Remaining to be fixed are 4 and 5.
      
    2. login: "sebres"
    3. mimetype: "text/x-fossil-wiki"
  3. Ticket change [cb865b8ea5] (rid 227591) by griffin on 2024-06-12 05:09:40:

    1. icomment:
      Thanks for uncovering these problems, and implementing the fixes.
      I will investigate/implement #4 & 5. I never considered big nums being used, but they should be supported.
      
      As for #3, it was intentional to have the string representation used to determine the number of significant fractional digits. It's the easiest and most straight forward way to write an lseq command and control the resolution of a floating point number sequence. It's how one can intentionally get: lseq 1.0 3.0 1 -> "1.0 2.0 3.0 4.0" versus lseq 1 3 1 -> "1 2 3 4".
      
      I'll review the changes in more detail in a few days, when I get the time.
      
    2. login: "griffin"
    3. mimetype: "text/plain"
  4. Ticket change [f23f179884] (rid 227644) by sebres on 2024-06-12 11:50:46:

    1. icomment:
      <blockquote><i>&gt; As for #3, it was intentional to have the string representation used to determine the number of significant fractional digits.</i></blockquote>
      
      It was clear to me. I only spoke about that it happens inconsistently.
      As I said sometimes (e. g. in expressions) round-able doubles causes integer series.
      For instance [./artifact?name=90d44fdab7ffb386&ln=4058-4061|this one] avoided that it'd return original double and therefore the [./artifact?name=90d44fdab7ffb386&ln=4182|trigger with useDoubles] would not be active.
      
      Let alone another corner cases, e. g. for large (or small) doubles like 1e50 the expression <code>floor(d) == d</code> could be theoretically true, but I doubt it'd work in C (in opposite to Tcl) due to integer overflow.
      
      <blockquote><i>&gt;It's how one can intentionally get: lseq 1.0 3.0 1 -> "1.0 2.0 3.0 4.0" versus lseq 1 3 1 -> "1 2 3 4".</i></blockquote>
      
      Yes, but not always. Here is an example where it was not so:
      <code><pre style="padding-left:2rem;">
      % lseq        1.0            3.0     1
      1.0 2.0 3.0
      % lseq [expr {1.0+0}] [expr {3.0+0}] 1
      1.0 2.0 3.0
      % lseq       {1.0+0}        {3.0+0}  1
      <span style="color:red;">1 2 3</span>
      % lseq       {1.1+0}        {3.1+0}  1
      1.1 2.1 3.1
      &nbsp;
      % lseq [expr {1e50+0}] [expr {1e50+1}]
      1e+50
      % lseq       {1e50+0}        {1e50+1}
      <span style="color:red;">bad operation "1e50+0": must be .., to, count, or by</span>
      </pre></code>
      
      This is exactly what one'd call inconsistency. So I fixed it during my review together with other stuff.
      
    2. login: "sebres"
    3. mimetype: "text/x-fossil-wiki"
  5. Ticket change [720563c12f] (rid 227673) by sebres on 2024-06-12 19:04:49:

    1. icomment:
      [c279bfc1b2b30cc1] fixes #5 (lseq will not swallow expr errors anymore).
      
    2. login: "sebres"
    3. mimetype: "text/x-fossil-wiki"
  6. Ticket change [8f141c10b2] (rid 227695) by sebres on 2024-06-12 20:21:20:

    1. closedate changed to: "2460474.34815096"
    2. closer changed to: "sebres"
    3. icomment:
      [362b0c5c71c2220d] fixes the last issue here, at the moment by throwing a simplest error "integer value too large to represent" (also covered by test lseq-1.16.2) as long as bignum series are not supported completely.
      
      If they get supported once, assignNumber (and test) can be adjusted to newest algorithms.
      
      Thus I'll close the ticket for now as fixed.
      
    4. login: "sebres"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"