I've got some code where I need to check if a vari...
# lucee
d
I've got some code where I need to check if a variable is an instance of a specific component. The appropriate function to call would be
isInstanceOf()
, but this has huge performance impacts (I'm still on Lucee 5.4.6.9). See https://luceeserver.atlassian.net/browse/LDEV-4905 for details. What's the fastest way to verify if a variable is an instance of a specific component? The fastest method I've found so far is to use
getMetaData()
and check the component name, but I feel like there's still got to be a faster way. Using
isInstanceOf()
the code I'm testing will take 15-30 seconds to run. Using
getMetaData()
, the time drops down < 1s.
b
20-30 seconds for a single call?
You could modify the init of every single CFC in your code base to do something like this
Copy code
this.className = getMetadata( this ).mame;
and then check it as
Copy code
someInstance.className ?: ''
That could have unwanted overhead in your inits though. I know Lucee caches metadata, but I'm not sure if it's cached per instance or per class
d
No, not 20-30 seconds for a single call of
isInstanceOf()
. The code triggers the execution of it a few thousand times. The code is executed when evaluting how to hand processing some code being lazy loaded.
z
same issue with the latest 6.2.2.1?
how slow is
getMetaData()
?
using a native cfml function to get the type of a cfc is a better path than the java approach, from your stack, it's falling back on reflection
d
I can't say about 6.2.2.1 (cannot easily test under 6). The performance of
getMetaData()
is much better than
isInstanceOf()
. Same exact code, using
isInstanceOf()
seems to average about 20-40ms per call, where as
getMetaData()
is < 2ms. The problem with
isInstanceOf()
I think is do to the synchronization locks happening internally, as least that's what I've found before and documented in LDEV-4905. I'm not sure why
isInstanceOf()
is so slow in these use cases. Perhaps it's because it's ultimately being triggered as part of a work flow that goes through a
createDynamicProxy()
call and might indeed be stuck doing some reflexion.
For the time being, I was able to replace one of the
isInstanceOf()
with a simple
isObject()
call that checks for a specific method. That reduced a ton of overhead. Just weird that it's so slow.
z
fyi, just tried your repo from that ticket, I'm getting 350 rps with 8 threads with 6.2.2.1?
d
You may need to tweak the jMeter thread counts. I know that particular test case seemed to vary a bit by environment, but hopefully 6.2.2.1 resolves the issues.
z
tried 4, 8 and 20, all the same more or less
d
good to hear!
z
do you ever use jfr ?
d
JFR?
z
java flight recorder
d
No. 🙂
z
really fucking cool n lightweight, you can use it on prod, has 2% overhead https://www.oracle.com/java/technologies/jdk-mission-control.html
d
I'll have to check that out. I have FR in use in my Dev environment, so I usually just use that to get insight into the performance of a request.
b
The FR profiler is 🔥 for seeing what a slow request is doing
20-30 seconds should give you a ton of data
And for anyone who's never used the FR profiler, here's a quick screencast I did a while back about it

https://www.youtube.com/watch?v=kr9MmMlpPnQâ–¾