Welcome Guest, Not a member yet? Register   Sign In
How does loading libraries happen?
#1

I mean on the physical file level. Are the files being copied or we just letting a class know where to look for it?

I guess it would be a lot easier if we could just autoload all libraries, but I dont think it is recommended because it will affect performance. Why?
Reply
#2

When you load a library it includes() the file and instantiates it (for libraries since you asked about that). Yes it would be "easier" to autoload everything, but it's also quite wasteful as you are loading things that not every "page" needs to use, but it has to load it anyway which takes time and uses memory. It might not be a big deal for a tiny website, but when you build very large projects where thousands of people are accessing it, these optimizations matter quite a lot. Things that are used on the majority of your website could be autoloaded, such as an authentication library. If you'd really like to know, just look at /system/Loader.php and see how it loads the libraries.
Reply
#3

Ah, includes() + instantiation - yea that can be very heavy. Thank you!
Reply
#4

You're wrong, autoload doesn't work like that, an autoloader will only load the "resources" you need, it's "on demand".
Reply
#5

@edellascenza

i am afraid you are miss-informed. any library,driver,helper,config,model specified in autoload.php will be loaded and instantiated. The autoload system is not an on-demand system as CI has no clue at time of loading these items which ones you would need or not need. So what CroNiX has said IS correct.
"I reject your reality and substitute my own" - Adam Savage, M5 Inc.
Reply
#6

(03-10-2015, 07:54 AM)lexxtoronto Wrote: I mean on the physical file level. Are the files being copied or we just letting a class know where to look for it?

I guess it would be a lot easier if we could just autoload all libraries, but I dont think it is recommended because it will affect performance. Why?

(03-11-2015, 04:01 AM)Hobbes Wrote: @edellascenza

i am afraid you are miss-informed. any library,driver,helper,config,model specified in autoload.php will be loaded and instantiated. The autoload system is not an on-demand system as CI has no clue at time of loading these items which ones you would need or not need.  So what CroNiX has said IS correct.

I was referring to PHP autoload NOT CI
Reply
#7

(03-11-2015, 05:11 AM)edellascenza Wrote: I was referring to PHP autoload NOT CI
The question wasn't about how PHP autoloads things, it was specifically about CI.
Reply
#8

Thank you all, yes I was asking about CI autoload. And it was useful to know how PHP autoload works too. Too much knowledge never hurts.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB