I like to keep my custom code as separated as possible (in the way it makes sense). In D7 I know it could be crucial (source) because every module used it's .module file and since module files getting loaded in each request it ended up having heavy page load times.

Since in D8 the .module file is not necessary to have any more, is the situation got better?

  • Just because there is no module file, doesn't mean nothing gets loaded :) However, D8 uses a nifty autoloading structure so that classes are only loaded when required. The way this can be done is by the use of services yml files, which gives a clear and lean way of indicating which file or class is where. This, in theory, should make for a very fast experience. I wouldn't worry too much about having too many custom modules, but the way we do it in our big project is by doing absolutely everything in just one module file, with a very complex and deeply nested class and folder structure. May 16, 2017 at 9:51
  • In D7 I know it could be crucial Where did that info come from though? Have you actually tested the theory? Unless you've got a particularly slow server, and/or modules with millions of lines of code in them, you should be talking microseconds - hardly a "crucial" delay
    – Clive
    May 16, 2017 at 10:49
  • @Clive Changed the original post, added the source!
    – ssibal
    May 16, 2017 at 11:26
  • I would take that discussion with a pinch of salt to be honest @ssibal, it doesn't ring true. Offsetting the load of multiple .module files by consolidating everything into one, but then separating that code back out into separate include files again when it gets too big? That doesn't feel particularly scientific to me. And the parsing argument doesn't really hold any more, we have opcache built into the language now. IMO you're in the realms of premature over-optimisation here - generally speaking you only optimise when you've already identified a problem.
    – Clive
    May 16, 2017 at 11:52
  • This is exactly what I wanted to know! Could you please copy/rephrase your comment into an answer? So I could accept it!: )
    – ssibal
    May 16, 2017 at 12:00


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.