Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#5201 closed Enhancement (fixed)

tr_variantDict could be much faster

Reported by: jordan Owned by: jordan
Priority: Normal Milestone: 2.80
Component: libtransmission Version: 2.75
Severity: Normal Keywords:


The cost of parsing, serializing, and searching tr_variantDict is really high. This is especially clear when using transmission-qt as a remote control.

In general, the biggest cost is searching for keys in the dictionary. We currently store the keys as strings, and for historical reasons the dictionaries are unsorted, so lookups involve a lot of memcmps. In addition, memory management for the strings makes up a nontrivial percent of overhead in transmission-qt.

There are a few things we could do to improve this:

  1. libtransmission could support a string-to-unique-int mapping similar to glib's GQuark and xlib's XrmQuark?. Using quarks internally as keys in tr_variantDict will shrink the size of the dict (by replacing half the tr_variant entries with an int field for the key), require less memory management (since the keys will be ints instead of memory-managed strings), and will speed up lookups (key comparisons will be int-to-int instead of string-to-string).
  1. Since libtransmission isn't a general purpose library like glib, we know ahead of time what nearly all of the dictionary keys will be -- .torrent files, pex messages, fast peer messages, the resume file, and our JSON RPC methods are all known. We can hardcode the string<->int mappings for the known keys and keep them in an enum for easy reference, as lib did with xatom.h's XA_* constants. This way all our code can refer to the symbolic constants of the quark directly instead of having to look them up.
  1. There is also some low-hanging fruit in serialization / deserialization. For example we set the LC_NUMERIC locale to ensure that a decimal place is a '.' as required by JSON. We're currently setting this each time we need to write a floating point... instead we should set it once when we start serialization.

Change History (4)

comment:1 Changed 8 years ago by jordan

r13683: first drop of the tr_quark patch

r13684: mac xcode support for tr_quark

r13685: change the #include of quark.h in variant.h

r13687: more tr_variant revision: faster serialization, dictionaries use less space

comment:2 Changed 8 years ago by jordan

  • Status changed from new to assigned

comment:3 Changed 8 years ago by jordan

  • Resolution set to fixed
  • Status changed from assigned to closed

comment:4 Changed 8 years ago by jordan

r13712: don't test to see if each dictionary value that's a string is a quark... it almost never is, so the lookup isn't worth it.

Note: See TracTickets for help on using tickets.