Port35x/tc optimize env var

A port from 3.2.x to 3.5.x