improve performance for toplevel program string generation (about 50% gain on average)