Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How file size affect performance?

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 only 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.

like image 950
zod Avatar asked Apr 18 '26 03:04

zod


1 Answers

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.

like image 70
Matthew Avatar answered Apr 20 '26 17:04

Matthew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!