Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

further optimization #54

Open
micrat opened this issue Apr 23, 2021 · 4 comments
Open

further optimization #54

micrat opened this issue Apr 23, 2021 · 4 comments
Assignees

Comments

@micrat
Copy link

micrat commented Apr 23, 2021

Hello developer, thanks for the useful script.
Here annexed a further optimization, based on version 1.46, in the hope that it could be useful.

  • [better performance] all empty lines or lines starting with # in the raw file are stripped out
  • [security] set attribute read-only to the hosts file

Hosts_UpdateA.zip

@ScriptTiger
Copy link
Owner

[better performance] all empty lines or lines starting with # in the raw file are stripped out

Are you using the script with compression settings? Because this hosts file is so streamlined already, most systems will never experience an issue requiring optimization. However, there are some select builds of Windows systems that do run into issues related to line count, not file size. For these cases, the script contains options for compression levels where you can condense multiple host entries to a single line. When a compression level is selected, all multi-line comments are condensed to a single line and the performance impact by keeping these comments has been found to be negligible. The reason why these comments are intentionally kept is for debugging purposes, which far outweigh any possible negligible performance cost.

[security] set attribute read-only to the hosts file

I do really like this idea and I'm actually curious why this has never come up before. It's not a super strong security measure, but every layer of security definitely helps. I think a bigger security enhancement could also be changing the user and group permissions, as well. As of right now the script doesn't explicitly change any attributes or permissions, so I think just reinforcing the best practice attributes and permissions for the hosts file would be a good idea.

Anyone else have any further input on these? I would personally like to see the security enhancements in the next release.

@micrat
Copy link
Author

micrat commented Apr 26, 2021

Yes, I can confirm the bottleneck on some windows systems is the number of lines.
A comparision I just performed gives the following results:

  • the original hosts base "raw" file counts about 90.0k lines
  • the vanilla script with compression level 9 reduces hosts to about 15.3k lines
  • the modified script with compression level 9 reduces hosts to about 9.3k lines

My conclusion is that the vanilla script already performs good job and the 15.3k lines hosts file is surely useful (on some systems it is a life changer!).
Mine is just a further optimization (the impact is much less important but is however appreciable during normal operations). And yes, this further optimization could be associated to a script option (or, for instance, setting compression level to a number greater than 9 could activate the 9-host-entries-per-line PLUS the further optimizations).
EDIT: here an example with optional optimization (15 entries-per-line + strip "#" and empty lines) activated with compression level A (only partially tested)
Hosts_UpdateB.zip

@ScriptTiger
Copy link
Owner

I'll take a look at implementing some additional options, as well as wait for further contributor input. I do value your feedback, so please rest assured and there is no need to continue to follow up on this at this time.

EDIT: here an example with optional optimization (15 entries-per-line + strip "#" and empty lines) activated with compression level A (only partially tested)

I can tell you right now 15 entries per line does not work on a Windows system as a Windows system can only parse 10 delimited chunks. In a hosts file, the 10 chunks are first the black hole IP address, and then the 9 host entries, each chunk delimited by white space.

ScriptTiger added a commit that referenced this issue Apr 27, 2021
Addresses the following issue:
#54
ScriptTiger added a commit that referenced this issue May 24, 2021
Addresses the following issue:
#54
@ScriptTiger
Copy link
Owner

Just pushed the update for making the hosts read-only. I have been a bit busy lately and was waiting to resolve the issue with PowerShell using TLS 1.2 first, which is also resolved in this update. Please update your script to make sure everything is working appropriately and let me know for confirmation.

[better performance] all empty lines or lines starting with # in the raw file are stripped out

Creating an option for this is the next thing on the to-do list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants