Use of .keyExists() can needlessly use memory in requests, suggest StructKeyExists() instead

Description

This is most impactful in places where the struct being queried in Lucee is not a regular struct but some other object like a scope. For instance in *RequestService.cfc$getContext()*:

 

1 2 3 4 5 function getContext( string classPath = "coldbox.system.web.context.RequestContext" ){ return ( request.keyExists( "cb_requestContext" ) ? request[ "cb_requestContext" ] : createContext( classPath ) ); }

Just changing this line to StructKeyExists() saved tens of megabytes in certain requests in our application.

StructKeyExists( request, "somekey" ) uses almost zero memory in my testing, where as request.keyExists( "somekey" ) takes around 10kb. Not huge, but can really add up in certain types of requests. The BIF is also faster.

Status

Assignee

Luis Majano

Reporter

Dominic Watson

Labels

None

Fix versions

Priority

Major