I did a bit more simplifying and I now have:

Object - abstract type for objects in a scene. Each has a method: 
intersect(config::Config, self::[object subtype], ray::Ray)
Sphere <: Object
Cube <: Object
Plane <: Object

I added skeleton code for AABB <: Object

   1. type AABB <: Object
   2.     colour::Float64
   3. end
   4. 
   5. function intersect(config::Config, self::AABB, ray::Ray)
   6.     return 1.0
   7. end
   

This code is never actually used.  And once I add it to my ray tracer the 
speed decreases by 25% (from 40s to 50s)

However this slowdown does not occur if
(a) type AABB is not a subtype of object
or 
(b) the signature for the intersection function changes. e.g. changing it 
to "intersect(config::Config, self::AABB, ray::Ray, x)

I think I've reached a weird case with multiple dispatch.  If this code is 
included, even though it is never called and I never instantiate an AABB 
object, the speed drops dramatically.

Notes:
* the intersect() functions are called a LOT
* all the intersect functions have the same signature of:  intersect(Config 
structure, an Object subtype, a Ray)
* changing the signature of the AABB intersect() function makes the 
slowdown disappear.

I hope this makes things a bit clearer.  Multiple functions with similar 
signatures shouldn't have this sort of speed penalty should they?  Is there 
any way of working around this?

Mik



Reply via email to