[RFC] Make getenv O(1)

Ondřej Bílka neleai@seznam.cz
Fri Oct 18 13:26:00 GMT 2013


On Fri, Oct 18, 2013 at 04:58:43PM +0400, Alexander Monakov wrote:
> Hi,
> 
> I'm curious about the motivation of this change.  Which programs are expected
> to benefit from faster repeated getenv queries?  (note that bash overrides
> getenv and co, so changes in glibc implementation won't affect it)
> 
Mostly those that call getenv in hot path. This mostly issue of
libraries, for example fnmatch checks getenv ("POSIXLY_CORRECT") so you
get definite slowdonw in following case.

time locate "[abc]aaa"
for I in `seq 1 10000`; do export FOO$I=$I; done
time locate "[abc]aaa"

You could argue that this does not help when likely case is that
variable is not defined. For that I would need posix say that changing
variable name via environ pointers is illegal.



More information about the Libc-alpha mailing list