Written by

Software Architect
Question Arun Kumar · Feb 1, 2018

Performance in Cache ObjectScript

Hi Guys,

Can you please advise on the below queries. 

Query 1:

Example 1:

 S a="345",b="arun",c="kumar",d="hi",e="yello",f="orange"

Example 2:

S a="345"

S b="arun"

S c="kumar"

S d="hi"

S e="yello"

S f="orange"

Can you please advise me, which one is performance wise is better. 

Query 2:

Example 1:

S:a=1 R="Arun"

Example 2:

I a=2 R="Arun"

Please advise me, which one is giving better performance in this. 

Any lead would be appreciated. 

Thanks,

Arun Kumar Durairaj. 

Comments

Robert Cemper · Feb 1, 2018

query 1 misses a variant:

set $lb(a,b,c,d,e,f)=$lb("345","arun","kumar","hi","yello","orange")

query 2,example 2 should be 

I a=2 SET R="Arun"
0
Arun Kumar  Feb 1, 2018 to Robert Cemper

Thanks for the query 1 new approach and correction of query2 example 2. 

Thanks a ton again. 

0
Alexey Maslov  Feb 1, 2018 to Robert Cemper

...Example1 is faster by less line terminations

AFAIK, line terminators are no longer stored in OBJ code since version 2010.1, so splitting a long code line into smaller ones can't affect performance at all.

0
Vitaliy Serdtsev  Mar 3, 2018 to Alice Shrestha

On my desktop quite other results.

  <FONT COLOR="#0000ff">n </FONT><FONT COLOR="#800000">N</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">j</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">time

  </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">N</FONT><FONT COLOR="#000000">=1e8

  </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">j</FONT><FONT COLOR="#000000">=1,2</FONT><FONT COLOR="#008000">/,3,4,5/ </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">j</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">") "

    </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$zh     d </FONT><FONT COLOR="#000000">@(</FONT><FONT COLOR="#008000">"j"</FONT><FONT COLOR="#000000">_</FONT><FONT COLOR="#800000">j</FONT><FONT COLOR="#000000">)(</FONT><FONT COLOR="#800000">N</FONT><FONT COLOR="#000000">)     </FONT><FONT COLOR="#0000ff">w $zh</FONT><FONT COLOR="#000000">-</FONT><FONT COLOR="#800000">time</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">" s."</FONT><FONT COLOR="#000000">,!   </FONT><FONT COLOR="#800080">}   </FONT><FONT COLOR="#0000ff">q </FONT><FONT COLOR="#ff0000">j1</FONT><FONT COLOR="#000000">(N) </FONT><FONT COLOR="#0000ff">public </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#800000">N </FONT><FONT COLOR="#800080">{</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">b</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">d</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">e</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">f</FONT><FONT COLOR="#000000">)=0</FONT><FONT COLOR="#800080">} } </FONT><FONT COLOR="#ff0000">j2</FONT><FONT COLOR="#000000">(N) </FONT><FONT COLOR="#0000ff">public </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#800000">N </FONT><FONT COLOR="#800080">{</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">=0,</FONT><FONT COLOR="#800000">b</FONT><FONT COLOR="#000000">=0,</FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">=0,</FONT><FONT COLOR="#800000">d</FONT><FONT COLOR="#000000">=0,</FONT><FONT COLOR="#800000">e</FONT><FONT COLOR="#000000">=0,</FONT><FONT COLOR="#800000">f</FONT><FONT COLOR="#000000">=0</FONT><FONT COLOR="#800080">} } </FONT><FONT COLOR="#ff0000">j3</FONT><FONT COLOR="#000000">(N) </FONT><FONT COLOR="#0000ff">public </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#800000">N </FONT><FONT COLOR="#800080">{</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">=0,</FONT><FONT COLOR="#800000">b</FONT><FONT COLOR="#000000">=1,</FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">=2,</FONT><FONT COLOR="#800000">d</FONT><FONT COLOR="#000000">=3,</FONT><FONT COLOR="#800000">e</FONT><FONT COLOR="#000000">=4,</FONT><FONT COLOR="#800000">f</FONT><FONT COLOR="#000000">=5</FONT><FONT COLOR="#800080">} } </FONT><FONT COLOR="#ff0000">j4</FONT><FONT COLOR="#000000">(N) </FONT><FONT COLOR="#0000ff">public </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#800000">N </FONT><FONT COLOR="#800080">{</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">=0 </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">b</FONT><FONT COLOR="#000000">=1 </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">=2 </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">d</FONT><FONT COLOR="#000000">=3 </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">e</FONT><FONT COLOR="#000000">=4 </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">f</FONT><FONT COLOR="#000000">=5</FONT><FONT COLOR="#800080">} } </FONT><FONT COLOR="#ff0000">j5</FONT><FONT COLOR="#000000">(N) </FONT><FONT COLOR="#0000ff">public </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#800000">N </FONT><FONT COLOR="#800080">{</FONT><FONT COLOR="#0000ff">s $lb</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">b</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">d</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">e</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">f</FONT><FONT COLOR="#000000">)=</FONT><FONT COLOR="#0000ff">$lb</FONT><FONT COLOR="#000000">(0,1,2,3,4,5)</FONT><FONT COLOR="#800080">} }</FONT>

Results:
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^perf</FONT>
  1. 11.814189 s.
  2. 4.683832 s.
As you can see the difference is almost 2.5 times.
0
Robert Cemper · Feb 1, 2018

Query 1 Example 1 could be marginally faster by less line terminations and less command dispatch:
But as this will be compiled some kind of code optimizer eventually might run.

Query2 Example1 is faster by less line terminations and less command dispatch.
BUT:  Both cases aren't the place to win benchmarks. Rather look for Global access , SQL optimizing, ....

0
Andre Cerri  Mar 1, 2018 to Eduard Lebedyuk

Totally agree, way more important to produce readable easily supported code, especially by non-Caché folk.

0
Robert Cemper  Feb 1, 2018 to Alexey Maslov

I wasn't sure.
therfore:  .... some kind of code optimizer eventually might run.

I remembered a discussion around Java JIT compiler and XEP being faster on globals that pure COS.
But I can't remember any result or consequences.

0
Eduard Lebedyuk · Feb 1, 2018

It's better to use more readable approach in these cases. It's somewhat doubtful that your app spends much time on local sets.

Use ^PERFMON to track performance issues. Also @Murray Oldfield wrote a series of articles on performance, check it out.

0
David Loveluck · Feb 1, 2018

https://community.intersystems.com/post/apm-finding-expensive-parts-you…

also describes how to locate expensive points in your code.

In this case you are talking about tiny differences. If this is executed millions of times in  a common path  that is executed frequently you might want to  think about it, but  for most applications it is not an issue. Those SQL queries that don't use an index are the killers.

0
Vitaliy Serdtsev · Feb 2, 2018

I also want to note that <FONT COLOR="#0000ff">s </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">b</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">)=0</FONT> is slower than <FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">a</FONT><FONT COLOR="#000000">=0,</FONT><FONT COLOR="#800000">b</FONT><FONT COLOR="#000000">=0,</FONT><FONT COLOR="#800000">c</FONT><FONT COLOR="#000000">=0</FONT>

0
Alice Shrestha · Mar 1, 2018

To answer your question via timed tests:

Query 1 (Iterating 100 million times...) :

Example 1 :

w $ZTS F i=1:1:100000000 {S a="345",b="arun",c="kumar",d="hi",e="yello",f="orange"} w !,$ZTS                                                              
64708,68916.71
64708,68926.342
~9.632 secs

Example 2

w $ZTS F i=1:1:100000000 {S a="345" s b="arun" s c="kumar" s d="hi" s e="yello" s f="orange"} w !,$ZTS                                                    
64708,68900.72
64708,68910.376 
~ 9.656 secs

Query 2 (Iterating 1 billion times!!!): 

Example 1:

w $ZTS F i=1:1:1000000000 {S:a=1 R="Arun"} w !,$ZTS                       
64708,69223.394
64708,69246.773
~ 23.379 secs

Example 2:

w $ZTS F i=1:1:1000000000 {I a=2 S R="Arun"} w !,$ZTS
64708,69264.946
64708,69289.174
~ 24.228 secs 

@  Vitaliy Serdtsev (100 million iterations)

w $ZTS F i=1:1:100000000 {s (a,b,c)=0} w !,$ZTS
64708,69571.214
64708,69577.797
~6.583 secs
w !,$ZTS F i=1:1:100000000 {s a=0,b=0,c=0} w !,$ZTS
64708,69589.118
64708,69595.433
~6.315 secs
w !,$ZTS F i=1:1:100000000 {s a=0 s b=0 s c=0} w !,$ZTS
64708,69793.562
64708,69799.545
~ 5.983

As everyone said, setting variables/ conditional statements is probably not where it's getting slow. As someone mentioned PERFMON is a great tool . Another one is ^%SYS.MONLBL. 

I just got too much bloody time .... 

0