Performance in Remote EJB’s

In a number of projects, we have to use @Remote EJB's. There are pros and cons for using @Remote EJB's, but in some cases the pros outweigh the cons. At least in GlassFish, you can boost the performance of remote EJB's relatively easily.

In case the client is in most cases running in the same VM, you can instruct the EJB container in GlassFish to pass values by reference where possible. You have to create a sun-ejb-jar.xml file in the META-INF directory of the ejb-jar, and in the entry describing the ejb, you have to add

 <pass-by-reference>true</pass-by-reference>

For the full syntax, see https://glassfish.dev.java.net/javaee5/docs/ADG/beaqi.html

Is this the most clean way to do this? Probably not. I'm not going to win the prize for the cleanest performance improvement. But important, it won't break Java EE compatibility, since it is not in an official Java EE deployment descriptor.
And at least for me, it works great.