optimization - Erlang: optimize complex qlc -
i have qlc
refsblocked = qlc:e(qlc:q([ ref1 || {{ref1, {pattern, {_status1, _pattern1, limit1}}}, count} <- dict:to_list( qlc:fold( fun({key, _ref2}, acc) -> dict:update_counter(key, 1, acc) end, dict:new(), qlc:q([ {{ref1, {pattern, {status1, pattern1, limit1}}}, ref2} || {ref2, {status, status2}} <- ets:table(tmp), {ref3, {tag, tag3}} <- ets:table(tmp), ref2 =:= ref3, {ref1, {pattern, {status1, pattern1, limit1}}} <- ets:table(tmp), ref =:= ref1, status1 =:= status2, pattern1 =:= tag3 ]) ) ), count >= limit1 ], unique)) where tmp ets of type bag , ref particular identifier need test.
ets contains from hundreds thousands of entries
{ref1, {definition, {tuple1}}} {ref1, {status, scheduled}} {ref1, {status, blocked}} {ref1, {pattern, {scheduled, pattern11, limit11}}} {ref1, {pattern, {dispatched, pattern12, limit12}}} {ref1, {tag, tag11}} {ref2, {definition, {tuple2}}} {ref2, {status, scheduled}} {ref2, {status, dispatched}} {ref2, {pattern, {scheduled, pattern21, limit21}}} {ref2, {pattern, {dispatched, pattern22, limit22}}} {ref2, {tag, tag21}} {ref3, {definition, tuple3}} {ref3, {status, error}} i. e. each ref there 1 definition, 1 or 2 (of four) statuses, 0 or more (in cases no more 3) patterns , 0 or more (in cases no more 3) tags.
i need test whether 1 particular identifier blocked others. blocked when number of identifiers matching of patterns on tag = pattern , status = pattern status more or equal pattern limit.
is there way optimize qlc?
unless have different, more efficient equality relation use, code have there gets. imagine you've profiled code , found slow? in way?
Comments
Post a Comment