Hi, guys, I want to know does using lot’s of dependencies slow down the run time of an endpoint?


#1

Hi, guys, I want to know does using lot’s of dependencies slow down the run time of an endpoint?

For example:

BaseController.js

'use strict'

const User = use('App/Models/User')
const Role = use('App/Models/Role')

class BaseController {
  constructor(){
    // Models
      this.User = User
      this.Role = Role
   }
}

UserController.js - version 1 - extending BaseController

const BaseController = use('App/Controllers/Http/Api/V1/BaseController')

class UserController extends BaseController {
    async index({ response }) {
        const user = this.User.find({})
        return response(user)  
    }
}

UserController.js - version 2 - defining only things that will be used at the controller

const User = use('App/Models/User')

class UserController {
    async index({ response }) {
        const user = User.find({})
        return response(user)  
    }
}

the question is does UserController version 2 runs a bit faster than UserController version 1?
or the speed is just a the same even if UserController v1 added Role Model even though it is not being used?

I’m a beginner at NodeJS and doesn’t understand how things work underneath. Help is greatly appreciated!


#2

Not at all. Requiring files is not that of an expensive operation and also require caches the code after requiring it once.

Don’t get into micro performance mindset, you will waste lots of time.


#3

Thank You!

This is what I really need to know.

:smiley: