I'm not sure, probably not that much, but it depends on whether the AddRef / Release functions are called a lot. If we use GetContainer, it would make a call to QueryInterface. If the surface hasn't got a container it makes a call to GetDevice and returns the wined3d device. We'd have to account for that as well. Or we could write a function to just retrieve the pointer. We would of course also have to get the d3d9 parent of the container.
I think the returned device pointer is not a problem - just check the returned pointer against your device instead of NULL. As for GetParent / QueryInterface / GetContainer calls, it's necessary to release any unwanted increased refcount. If however, a GetContainer call for an D3D9 texture causes an AddRef or Release of that texture, the approach is impossible. I didn't find any evidence of that yet.
I'm not sure if it happens or not (and if it is actually required when it happens :)), but the function to change it is there. Of course if we can be sure it never happens that would mean we could just store the pointer to the container in d3d9 during creation time and set it to NULL when releasing the container.
That would make everything much easier :)
I'd suggest that you send a patch taking whatever way you like, and ask AJ for his opinion.