The best approach will probably be to (re)design your application to avoid string copies where possible, e.g. use ngx.re.find instead of ngx.re.match, string.find instead of string.match, etc. In some cases, string creation is unavoidable, such as when reading request/response data into the Lua land, so be smart about where you create new strings, and where you can reuse existing ones :)