etnt / gettext

Erlang internationalization library.
http://www.redhoterlang.com/
MIT License
70 stars 45 forks source link

Optimize phrase access speed via public ETS #19

Open seriyps opened 10 years ago

seriyps commented 10 years ago

Add {read_concurrency, true} option to ETS table and lookup it directly, bypasing gen_server:call. This may be done without any API changes.

etnt commented 10 years ago

Lookup directly...hm I wonder if someone running gettext in a distributed setting where the server only runs on a specific node? I don't remember how Klarna (a big user of gettext) does.

seriyps commented 10 years ago

I think, it may be optional, by setting flags in gettext_server's process dictionary like

key2str(Server, Key, Lang) ->
    case proplists:get_value(public_table, erlang:process_info(Server, dictionary)) of
        undefined ->
            gen_server:call(Server, ...);
        Tid ->
            ets:lookup(Tid, ...)
    end.

Which is quite fast and don't require any message-passing.

etnt commented 10 years ago

I would be very cautious to add anything hidden under key2str/3 since it is really heavily called in large systems such as Klarnas. I don't like the proplists module at all, and doing a process_info call, involving another process, may have uncertain side effects (e.g being re-scheduled?).