RTD server : performances issues

407 views
Skip to first unread message

Ron

unread,
Mar 21, 2011, 12:28:26 PM3/21/11
to Excel-DNA
Hi,

I may be obsessed with RTD server and functions returning arrays but I
have a new issue (may be related to the ServerStart one ?).

I have one function (let's call it "Pulse") which updates whatever,
and it ends by the notification of the callback.
I have another function ("CountCalls") which displays whatever, but
through an array. Each time "Pulse" notifies the callback, the
"RefreshData" function returns the topic id of the cells calling
"CountCalls".

In my spreadsheet, I call "CountCalls" just one time, but as an array
in 4 cells. Now, when I call "Pulse" and later press F9 (I am in
manual calculation mode), then "CountCalls" is called 4 times ! It
should be called just once.

I can change 4 by any number of cells, "CountCalls" will be called
that number of times.

Obviously, if I manually call "Test" as an array in Excel, then only
one call of "CountCalls" will be done in my program.

I observe that it does not work in this way every time, but it is easy
to reproduce it.


Something funny : you can try with this implementation of CountCalls

private static int count = 0;

[ExcelFunction(Name = "CountCalls")]
public static object CountCalls()
{
++count;

XlCall.RTD("Test.RTDServer", null, null, null);

object[,] ret = new object[2,1];
ret[0, 0] = count;
ret[1, 0] = count;

return ret;
}

If you call it manually, you will have "1" in every cells. If you call
"Pulse" and later press F9, then the cells won't have the same value !

It seems that for each cell concerned by the array, an individual call
to the function will be done.

So finally, calling 100 times a scalar function becomes faster than
calling one time a function returning an array of size 100.

I can give you more precise example.

Thanks
Ron

Govert van Drimmelen

unread,
Mar 21, 2011, 4:35:44 PM3/21/11
to Excel-DNA
Hi Ron,

Thank you very much for your continued exploration of the RTD
interface, and for posting your findings.

I also see the multiple calls you do. I've checked with a regular RTD
server (no Excel-DNA) and a VBA wrapper, and the behaviour is the
same. The wrapper is called once for every cell in the array, and the
corresponding entry in the result array is used from each call.

From what I see in this KB article: http://support.microsoft.com/kb/286258,
it seems RefreshData is not called many times, just the wrapper.

Good to know about this - so it would seem better to try to design the
RTD interface and topics so that you can use them from single cells.

-Govert

Montgomery Panzram

unread,
Mar 22, 2011, 1:27:24 AM3/22/11
to Excel-DNA
Hi Ron,

I have also noticed some of the issues you bring to light. I found
that I could eliminate a few of them if I set a select functions to
IsVolatile. The solution is not without drawbacks, but I got it to
work as it should at least.

Regards

Ron

unread,
Mar 22, 2011, 5:37:59 AM3/22/11
to Excel-DNA
Hi Govert,

It is not really a good news but it is good to know. Hopefully, I just
began to design my application !
The article you pointed seems very interesting. I will try to
implement that solution and then I will post my feedback.

Thanks again.

Ron

Ron

unread,
Mar 22, 2011, 5:40:02 AM3/22/11
to Excel-DNA
Hi Montgomery,

Do you have a simple example to illustrate when it can bypass our
issue ?
I tried with my code and the behavior is still the same. But I am
curious, perhaps in some context I could use that.

Thanks
Ron


On Mar 22, 5:27 am, Montgomery Panzram <montgomery.panz...@gmail.com>
wrote:

Ron

unread,
Mar 22, 2011, 6:43:20 AM3/22/11
to Excel-DNA
I am afraid there's no hope !

Actually, helps to "Evaluate" function in VBA, you can return a string
through DNA and convert it into an array through VBA. It works very
well ; finally you just have to replace the following call in the
cells
{=MyFunction()}
by this one
{=parseArrayData(MyFunction())}
after having implemented "parseArrayData" (trivial).
But the function will still be evaluated many times.

Anyway, you can return whatever you want in your DNA function, the RTD
server will call it many times, even if it just returns a scalar
value.

So, I think that I have no other choice than not return arrays, and
build only scalar functions.
The good point is that I shall not meet the "ServerStart" issue
again ;)



On Mar 21, 8:35 pm, Govert van Drimmelen <gov...@icon.co.za> wrote:
Reply all
Reply to author
Forward
0 new messages