Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is listFindNoCase() and listFind() "much faster" than a simple OR / IS in CF?

I fail to understand, why is using listFindNoCase() and ListFind() the preferred way of doing a series of OR and IS/EQ comparison? Wouldn't the JVM be able to optimize it and produce efficient code, rather then making a function call that has to deal with tokenizing a string? Or is CF doing something much more inefficient??

Use listFindNoCase() or listFind() instead of the is and or operators to compare one item to multiple items. They are much faster.

http://www.adobe.com/devnet/coldfusion/articles/coldfusion_performance.html

like image 736
Henry Avatar asked Dec 16 '22 11:12

Henry


2 Answers

The answer is simple: Type conversion. You can can compare a 2 EQ "2" or now() EQ "2011-01-01", or true EQ "YES". The cost of converting (to multiple types ) and comparing is quite high.

ListFind() does not need to try multiple conversions, so it is much faster.

This is the price of dynamic typing.

like image 193
Paul Perigny Avatar answered Dec 18 '22 23:12

Paul Perigny


I find this odd too. The only thing I can think of is that the list elements are added to a fast collection that check if an element exists based on some awesome hash of the elements it contains. This would in fact be faster for large or very large lists. The smaller lists should show little or no speed boost.

like image 36
Sean Avatar answered Dec 18 '22 23:12

Sean