A
A
Andrew2018-07-24 16:01:58
JavaScript
Andrew, 2018-07-24 16:01:58

What is faster to import a local module or a global one?

there is a function from lodash that will be used in many parts of the application, for speed it would be better to make one import of the library into your function, and already use it throughout the application, or would it be acceptable to import the function itself from the library in all parts of the application?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Interface, 2018-07-24
@Interface

It must be imported in those modules where it is needed. Modules in node.js are cached https://nodejs.org/api/modules.html#modules_caching

I
Ilya Gerasimov, 2018-07-25
@Omashu

What's the point? At startup, all this is poured into memory, and does not constantly twitch from the disk, if the volume of modules is important, then in lodash you can connect only the necessary lodash / map functions (for example). You can also build the application and run it, but this is hardly necessary in the backend part.

T
throughtheether, 2014-12-12
@qmmp123

It is necessary to remove the slashes and what is between them.
Specify what exactly you want to get from the string
If the desired end result is Hatredcopter.mp3, then it's not easier to do this:
>>> filename='/home/user/develop/user/project/protatypes/Hatredcopter.mp3'
>>> if '/' in filename:
  filename=filename[filename.rindex('/')+1:]
>>> filename
'Hatredcopter.mp3'

And generally speaking, it is more correct, in my opinion, to process paths and file names using the functions of the os module:
>>> import os
>>> filename='/home/user/develop/user/project/protatypes/Hatredcopter.mp3'
>>> os.path.split(filename)
('/home/user/develop/user/project/protatypes', 'Hatredcopter.mp3')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question