开发者

How file size affect performance?

开发者 https://www.devze.com 2023-02-17 02:09 出处:网络
I need some clarification on the performance of a website. Assume server configuration is optimised and the same, just think about file size and number.

I need some clarification on the performance of a website.

Assume server configuration is optimised and the same, just think about file size and number.

  1. How the size of the file affect the performance of the website?

    Let's assume we have a file with 10000 lines and there is a function with 50 lines. We are calling o开发者_JAVA技巧nly that function. Nothing else is used at all.

Another file with this function alone of 50 lines.

  1. If we execute both files, will a small file will be faster or both will execute as same?

  2. Why we are trying to reduce the line of code?

Assume there are 1000 files on the server. We are using only 2 files. Another server having only 2 files. Will there be a difference between these 2 server files execution?

I am using PHP. But the question is general.


This is not something that can be answered with a yes or no. You would have to benchmark how many requests/second your application could handle to see. My opinion is that the difference is insignificant given a properly configured server.

If you use something like APC, the files get parsed once and stored into memory. At that point, the distribution of the lines of code is hardly relevant.

If you are not using something like APC, then you have two main things to consider:

  • File I/O time. Accessing multiple smaller files can be slower than accessing a large file.

  • Parsing time. Parsing a large file will take more time than a small one. If you are parsing more than you need, then you are wasting time.

But again, as most people will tell you, this is probably not something you need to worry about. And you definitely shouldn't worry about it if you cannot prove that it's a problem with benchmark and profiling tests.


If you are only "using" 50 lines out of a 10,000 line file, then yes you are losing some performance... in both speed for the PHP to parse the whole page even though it isn't using 9,950 lines of it - as well as "developer-hell" where the development time to find this function and understand that the other mountain of code isn't relevant.

That said, don't take a 10,000 line "utility" file, and split it into 500 separate files with 1 function in each of them... called randomly as needed (the opposite pain).


Well, here goes a clarification:

A code itself well be least thing to affect performance. And Assume server configuration is optimized is just empty blab. It's endless process and depends on many factors.
If you want to optimize something, you have to run profiling tests first, then determine a bottleneck and then optimize it.

There are many opcode caching solutions that makes your question totally obsolete.

Listen to good advise, do not ask questions "in general". Especially such useless and imaginary ones.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号