java - Reflection performance -
i have collection 1 100 objects of type. these objects have on 100 attributes. have traverse objects in collection , check attibutes them. actual methods depends on properties file cannot know beforehand 1 have call. have done reflection in way:
for (myobject mo : myobjectlist){ (propertydescriptor propertydescriptor : introspector .getbeaninfo(mo.getclass()) .getpropertydescriptors()) { method = propertydescriptor.getwritemethod(); if (method != null){ //here check if attribute in properties file , job } } } this implemented in webservice called several applications , load can theoretically high.
the reflection method computer expensive way found able task without changing code if tomorrow new attribute addressed task.
i have read (don't remember source) expensive part of reflection looking methods more calling them have been thinking maybe reversing loops (i.e. methods , call method reflection each object) performance wise change. this:
for (propertydescriptor propertydescriptor : introspector .getbeaninfo(myobject.getclass()) .getpropertydescriptors()) { if (method != null){ (myobject mo : myobjectlist){ //do job here } } } there grounds reversing loops?
have measured performance of ? suspect impact negligible compared network , marshalling overhead of webservice.
if genuinely think issue, can retrieve method objects in advance objects (or @ least perform operation in lazy fashion - when required , cache later use. note sotirios' comment above, , caching may redundant if so)
Comments
Post a Comment