Have added some static luv and moved some return statements up. With those changes get_username_string() uses 2% instead of 27%
Currently fairly untested code, it's more like a proof of concept at the moment
Patch has been attached.
Ps. small bug in the patch, one of the last lines should be '$mode == 'profile', not '$mode != 'no_profile')