Proposal
Add optional flags argument to shmdict_get(_stale)? that only returns value if flags do not match.
And a 3rd (4th for _stale) return value to indicate if it is a flag match.
Example usage
local object, stale_data, lru_flag = lru:get(key)
local serialized, shm_flag, flag_match = shm:get(key, object and lru_flag)
if flag_match then
return object
end
if serialized then
object, err = cjson.decode(serialized)
if object then
lru:set(key, object, 0, shm_flag)
end
return object, err
end
Why?
Allocating and collecting the memory nedded to return a value can be
very expensive when value is not needed.
Bencmarking
Link to benchmark repo
Read only benchmarking, with random access order.
Tested with 5 000 000 shm lookups on a single worker.
Value 2048 bytes string
Results: ~75.8% faster
Value 1024 bytes string
Results: ~46.8% faster
Value 256 bytes string
Results: ~24.7% faster
Value 16 byte string
Results: ~19.8% faster
Value number
Results: ~5.4% faster
Pull requests
Proposal
Add optional flags argument to
shmdict_get(_stale)?that only returns value if flags do not match.And a 3rd (4th for _stale) return value to indicate if it is a flag match.
Example usage
Why?
Allocating and collecting the memory nedded to return a value can be
very expensive when value is not needed.
Bencmarking
Link to benchmark repo
Read only benchmarking, with random access order.
Tested with 5 000 000 shm lookups on a single worker.
Pull requests