Overview
| Artifact ID: | 38f47a8fc21cfe456c79d8ece0929a919a9ee5fd |
|---|---|
| Ticket: | 1101710fffffffffffffffffffffffffffffffff
Enhanced "if" bytecoding for [if $e ...] |
| User & Date: | robert_seeger on 2005-01-13 15:30:56 |
Changes
- assignee changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
When bytecompiling [if $e ...] vs [if { [expr $e] } ..], the second version is faster, due to the bytecompiler for "if" not performing an optimization that it most likely could. Specifically, it can be seen in the information below that the "if" is just pushinhg "if" with the arguements and "invokeStk1", whereas the "expr" is adding the variable to the stack, then calling "exprStk", "tryCvtToNumeric", and "jumpFalse1". I believe the "if" command could benefit from doing the same as the "expr" command in this circumstance. ---- showing the problem ---- #!/bin/sh # This line continues for Tcl, but is a single line for 'sh' \ exec tclsh "$0" ${1+"$@"} set expr1 { 1 < 2 } time { if $expr1 {} else {} } 10000 time { if {[expr $expr1]} {} else {} } 10000 load ~/cvs/bytecode/libbytecode.so proc withBrace {e} { if { [expr $e] } { return 1} else { return 2 } } proc withoutBrace {e} { if $e { return 1} else { return 2 } } proc noVar {} { if { 1 < 2 } { return 1 } else { return 2 } } puts "--- withBrace: [time {withBrace $expr1} 100000]" puts "--- withoutBrace: [time {withoutBrace $expr1} 100000]" puts "--- noVar: [time {noVar } 100000]" puts "--- withBrace\n[bytecode::get withBrace]" puts "--- withoutBrace\n[bytecode::get withoutBrace]" puts "--- noVar\n[bytecode::get noVar]" return --- withBrace: 6 microseconds per iteration --- withoutBrace: 9 microseconds per iteration --- noVar: 3 microseconds per iteration --- withBrace Header {...} Procedure { ReferenceCount 1 NumArgs 1 CompiledLocals 1 Slots { 0 { Slot 0 Type {scalar arg} Name e} } } CompiledLiterals { 0 1 1 2 } ExceptionRanges {} Commands { 0 {Number 1 PC {0 13} Src {1 47} Code {"if { [expr $e] } { return 1} else { return 2 } "}} 1 {Number 2 PC {0 2} Src {7 13} Code {"expr $e"}} 2 {Number 3 PC {6 8} Src {20 27} Code {"return 1"}} 3 {Number 4 PC {11 13} Src {37 45} Code {"return 2 "}} } ByteCodes { 0 {Number 0 Name loadScalar1 Operands {{Type OPERAND_UINT1 Value 0 Note {var "e"}}}} 2 {Number 2 Name exprStk Operands {}} 3 {Number 3 Name tryCvtToNumeric Operands {}} 4 {Number 4 Name jumpFalse1 Operands {{Type OPERAND_INT1 Value 7 Note {pc 11}}}} 6 {Number 6 Name push1 Operands {{Type OPERAND_UINT1 Value 0 Note {"1"}}}} 8 {Number 8 Name done Operands {}} 9 {Number 9 Name jump1 Operands {{Type OPERAND_INT1 Value 5 Note {pc 14}}}} 11 {Number 11 Name push1 Operands {{Type OPERAND_UINT1 Value 1 Note {"2"}}}} 13 {Number 13 Name done Operands {}} 14 {Number 14 Name done Operands {}} } --- withoutBrace Header {...} Procedure { ReferenceCount 1 NumArgs 1 CompiledLocals 1 Slots { 0 {Slot 0 Type {scalar arg} Name e} } } CompiledLiterals { 0 if 1 { return 1} 2 else 3 { return 2 } } ExceptionRanges {} Commands { 0 {Number 1 PC {0 11} Src {1 36} Code {"if $e { return 1} else { return 2 } "}} } ByteCodes { 0 {Number 0 Name push1 Operands {{Type OPERAND_UINT1 Value 0 Note {"if"}}}} 2 {Number 2 Name loadScalar1 Operands {{Type OPERAND_UINT1 Value 0 Note {var "e"}}}} 4 {Number 4 Name push1 Operands {{Type OPERAND_UINT1 Value 1 Note {" return 1"}}}} 6 {Number 6 Name push1 Operands {{Type OPERAND_UINT1 Value 2 Note {"else"}}}} 8 {Number 8 Name push1 Operands {{Type OPERAND_UINT1 Value 3 Note {" return 2 "}}}} 10 {Number 10 Name invokeStk1 Operands {{Type OPERAND_UINT1 Value 5}}} 12 {Number 12 Name done Operands {}} } --- noVar Header {...} Procedure { ReferenceCount 1 NumArgs 0 CompiledLocals 0 } CompiledLiterals { 0 1 1 2 } ExceptionRanges {} Commands { 0 {Number 1 PC {0 14} Src {1 44} Code {"if { 1 < 2 } { return 1 } else { return 2 } "}} 1 {Number 2 PC {7 9} Src {16 24} Code {"return 1 "}} 2 {Number 3 PC {12 14} Src {34 42} Code {"return 2 "}} } ByteCodes { 0 {Number 0 Name push1 Operands {{Type OPERAND_UINT1 Value 0 Note {"1"}}}} 2 {Number 2 Name push1 Operands {{Type OPERAND_UINT1 Value 1 Note {"2"}}}} 4 {Number 4 Name lt Operands {}} 5 {Number 5 Name jumpFalse1 Operands {{Type OPERAND_INT1 Value 7 Note {pc 12}}}} 7 {Number 7 Name push1 Operands {{Type OPERAND_UINT1 Value 0 Note {"1"}}}} 9 {Number 9 Name done Operands {}} 10 {Number 10 Name jump1 Operands {{Type OPERAND_INT1 Value 5 Note {pc 15}}}} 12 {Number 12 Name push1 Operands {{Type OPERAND_UINT1 Value 1 Note {"2"}}}} 14 {Number 14 Name done Operands {}} 15 {Number 15 Name done Operands {}} } - foundin changed to: "None"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "robert_seeger"
- subsystem changed to: "None"
- title changed to: "Enhanced "if" bytecoding for [if $e ...]"
- type changed to: "RFE"