Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfc vs cfinclude. cfc seems slow

Explorer ,
Sep 21, 2009 Sep 21, 2009

Hi,

I'm getting started changing my old cf app to use CFCs.

I have a lot of include files that contain a single query.

so, in my pages I will have something like:

<cfinclude template="/query/selAllUsers.cfm">

I've been reading basic tutorials and a lot of them go through a process where they basically put this query inside a .cfc page and makes <cffunciton> for it.

So in testing I've done this but noticed that it seems so much slower...like 3 times slower!

Is putting these queries inside a CFC not the best thing to do? I understand the appeal of the CFC approach but it seems a bit silly that something that simple would slow my pages down so much.

Thanks.

TOPICS
Getting started
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Sep 21, 2009 Sep 21, 2009

<cfinclude...>

ColdFusion load this file and run the CFML just as if it was part of the CFML in the includeing file.

CFC Component.

Load this file.

Process the CFML and instantate it into an object then store the object in memory.

Run any requested functions against the object in memory.

On a one on one race the include will almost always win.

But if one doesn't use a CFC as an include function library.  And instead uses it as a lite object, then preforance can be gained.

But there are many other benifits to components as well.  So 98.74% of the time, there are imporvements to refactoring code that can be into components.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 22, 2009 Sep 22, 2009

Hi thanks for the response.

It turns out I was using <cfinvoke> too many times on the page. None of the tutorials I read bothered to mention that you only need to do it once for the page and then can access it like:

myComponenet.myMethod()

I switched to that and everything is speedy as ever!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 22, 2009 Sep 22, 2009

Hi thanks for the response.

It turns out I was using <cfinvoke> too many times on the page. None of the tutorials I read bothered to mention that you only need to do it once for the page and then can access it like:

myComponenet.myMethod()

For future reference, the best first port of call when getting up to speed with CF stuff is the official documentation.  Look up your topic of interest in there, and read the official line before looking for third-party tutorials.

Here's the relevant stuff for your situation:

http://livedocs.adobe.com/coldfusion/8/htmldocs/buildingComponents_15.html#1214389

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 25, 2009 Sep 25, 2009

Yes, I read that page already. I always look at the docs.

They say: "If you use a CFC multiple times in a ColdFusion request, or if you use a CFC with persistent properties, use the cfobject tag or CreateObject function to instantiate the CFC before you call its methods."

Ok, I get that now. But then they don't follow through and actually show you how to call it's methods with an example. Explanation is ok, but a good example is better. That's why I looked for tutorials as well.

Unfortunately, most of the tutorials I read (including Adobe-authored tutorials) glossed over this portion and only talked about cfinvoke, not mentioning that you only needed that once on the page.

Anyway, total newbie mistake, I realize. Thanks for the patience.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 25, 2009 Sep 25, 2009
LATEST

Just to note, depending on the intention of the query, you can also put the cfc (object) into either the application or session scope so it is not instantiated every time the page is called, but only once per session or once per application.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources