-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Getting Environment Variables is few times slower on Linux #866
Comments
I think, as a quick fix, that the check by length could be scrapped and just strcmp() could be used, if it doesn't use strlen() internally :-) Oh oh, I got now to profile the code and I see why strncmp is needed (because of = in env entries). |
dotnet/corefx#27632 did not solve the problem |
I've tried to implement strncmp as an explicit loop:
and the profiler shows a good improvement (based on 1E8 iterations over a list of 6 entries looking for the last entry): |
I've been able to shave off some percent: by rewriting the inner tests of the compare loop:
|
@Ulisse67 it would be great if you could run our benchmarks and confirm the improvements How to build CoreCLR in Release: ./build.sh -release
./build-test.sh release generatelayoutonly Once you run those two commands you should get an executable called Example: git clone https://github.com/dotnet/performance.git
python3 ./performance/scripts/benchmarks_ci.py -f netcoreapp5.0 --filter 'Perf_Environment' --corerun /home/adam/projects/coreclr/bin/tests/Linux.x64.Release/Tests/Core_Root/corerun |
It may be also worth looking at inlining check for the first character only that filters most of the negatives, and still call strncmp for the rest. |
I had finally the time to build CoreCLR on my machine (WSL1 within Win10) and have run the performance tests for a version with strncmp + lookahead(1): And then for a version using pointers:
|
It looks like you got 10% improvement, nice! |
Do I have to make a PR? |
Yes, please! We have merged CoreFX and CoreCLR repositories into https://github.com/dotnet/runtime, so please send your PR to the new repo |
Can environment variable names or values in Linux ever be non ASCII (ie., UTF-8)? If so will this "raw pointer" approach still be OK? (eg., will it see |
I believe the equal sign has one 8-bit code even in UTF-8; there are two other equal signs (above= and under=) which use 2 bytes each, but I don't think is legal for specifyfing an environment variable. Even using UTF-8 for keys would not invalidate the pointer (or strncmp()) approach, because UTF-8 is defined to be backwards compatible with zero-terminated strings, and thus all related idioms keep working. |
How to run the benchmarks:
Recommended profilers are PerfCollect and VTune.
The text was updated successfully, but these errors were encountered: