--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/9ff31e67-7a69-4b56-9fc2-bdbba70f1f11n%40googlegroups.com.
Hi Kasper,
It’s not quite the same – it implements the async call directly as an IObservable on top of the Task you pass in (actually the Task created from the delegate you pass in).
If the Task you pass in does not come from Task.Run, but is rather a C# async / await method with some ‘native’ async work like a network call where it awaits, then the work does not first have to get scheduled on the threadpool. The completion after the await (or between awaits) may or may not get scheduled on the ThreadPool, but seems more efficiently managed to me. Anyway, you basically get rid of your own IObservable implementation and use the Excel-DNA one, and you get to write the ‘implementation’ of the async function in a cleaner way as a Task-returning async/await function. So, even if there is no performance difference, it cleans things up a bit.
You should put a Debug.Print or something in the outermost function to see what I mean.
It gets called initially, and then the async completion causes it to be called again (with an internal structure having prepared the result).
The function name and argument array that you pass to ExcelAsyncUtil.Observe or RunTask… is the ‘key’ in the dictionary that keeps the result, so it’s looked up and returned from there.
If you make a ‘streaming’ function that returns many values to Excel, then the outer wrapper is called for every update.
So you want to make the outer bit (everything that runs before you call ExcelAsyncUtil.xxx) as simple and efficient as possible.
Rather capture all the arguments passed to the function as part of the delegate that you pass to ExcelAsyncUtil.xxx, and dop further processing inside the delegate.
The delegate only runs once per formula setup.
In your case this will probably not make a noticeable difference, but it’s a good pattern to get right early.
For a much more dramatic performance improvement, you can try to figure out how to make the async function work as batched calls to the back end (either your own back-end or even as batched calls to the api with some prompt tuning). That lets you have single cell async functions, but make far fewer calls to the back.
One example of how to approach this is here: Samples/AsyncBatch/AsyncBatch/AsyncBatchUtil.cs at master · Excel-DNA/Samples
Also keep in mind dynamic arrays, and whether you can make functions that can take and return arrays.
That works very well to improve the async granularity too.
Let me know if you have any other questions – it looks like a promising add-in and service.
Regards,
Govert
To view this discussion visit https://groups.google.com/d/msgid/exceldna/CAGGgHneRDBTnxTv3fGq_pE3SX-gC4yUu%3DeYtofa_h62ppaH%3D%3Dg%40mail.gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/03bb01dbd3ff%24ab095b80%24011c1280%24%40gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/1d3155bd-8d2a-4848-ba03-a3cde22608cen%40googlegroups.com.
Hi Kasper,
If you need the address of the passed in reference, then you do indeed need AllowReference=true.
-Govert
To view this discussion visit https://groups.google.com/d/msgid/exceldna/CAGGgHncrfHijKo0Ziha22wDvE1jgqqb0w9MEZ%3DaZLiU6vVv%3DxA%40mail.gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/00d701dbd53f%24bd8a6060%24389f2120%24%40gmail.com.