coldfusioncfquerycfinvoke

Which is faster: CFM page full of CFQUERY calls or CFINVOKE calls?


Which would be faster and more efficient memory-wise?

  1. A CFM file containing individual CFQUERY calls
  2. A CFM file containing individual CFINVOKE calls to CFC's containing individual methods for each of those same queries

I realize there are different ways of invoking methods of a component, such as using createobject. For now, let's limit the discussion to just the above two options.

I don't have any sample code. Just want to know what would be considered best practice in the above situation.

Also, I am using newer versions of Adobe ColdFusion (2016, 2018, 2021), so Lucee is not an option.


Solution

  • In short, option #2 is the recommended practice. You want to store back-end processing in CFC files, which act like objects of entity classes and controller classes, all as part of the CFM file, which acts as a presentation class. These protocols all stem from the object-oriented programming paradigm.

    Now, with using component methods generally being the better choice for holding queries, (1) it doesn't mean you are constrained to this option and (2) that doesn't answer the question of which performs better. Yet, the query should still probably be called from a component method. Since you have the same query, you can simply make one stateful query object and the data and the methods can be encapsulated in the same memory space, leading to an overall performance boost.