Lunderberg commented on PR #16183:
URL: https://github.com/apache/tvm/pull/16183#issuecomment-2276526876

   FOUND IT!
   
   The root cause was in the type validation, but ended up being pretty easily 
solveable.  When converting from the untyped `ArrayNode*` to the typed 
`Array<T>`, we validate that each `ObjectRef` in the array has the correct type 
`T`.  However, because each element in the untyped `ArrayNode*` must still be 
some type of `ObjectRef`, this check is unnecessary.
   
   In the test case, this performance overhead largely occurred during the 
calls to `"vm.builtin.tuple_getitem"`.  For each call, the validation function 
iterated over the entire `Array<ObjectRef>` argument.  This overhead can be 
removed by adding a compile-time check on the type parameter's type.  I've 
updated the conversions for both `Array<T>` and `Map<T,U>` to skip type checks 
that will always succeed.
   
   With this addition, the FFI update went from being 5x slower than baseline 
(increase from 1 ms to 5 ms) to being 30% faster than baseline (decrease from 
1ms to 700 us).  I'll make a PR shortly that re-applied the FFI changes, with 
the additional fix.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to