[librsvg: 95/95] gitlab#201 - Overhaul attributes parsing with perfect hashing (merge phf-attributes)
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 95/95] gitlab#201 - Overhaul attributes parsing with perfect hashing (merge phf-attributes)
- Date: Thu, 22 Feb 2018 03:21:07 +0000 (UTC)
commit a80298737e4f1abfd038d7feeeda8c980adea7b4
Merge: 4bb8914a 24450902
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Feb 21 21:06:54 2018 -0600
gitlab#201 - Overhaul attributes parsing with perfect hashing (merge phf-attributes)
Libxml2 hands us a NULL-terminated char** of key/value pairs for each
element's attributes.
We would store those pairs in a GHashTable to be able to do random
access on the list of attributes for each element - this was
RsvgPropertyBag.
However, big chains of lookups for "all the attributes" are slower
than necessary. Instead, we would rather process the attributes that
are actually present in each element, instead of trying to match all
elements for every known attribute to the styling system.
We now use a Perfect Hash Function to map attribute names to enum
values. We can then switch() in C, or match in Rust, over these enum
values - the compiler can optimize that very well.
We now have a Rust implementation called PropertyBag, which wraps
libxml2's array of key/value pairs. It uses iteration rather than
lookups, and avoids string copies.
This produces a good minor speedup. Across 5588 SVG icons on my
machine:
2.42.2 - 10.25 sec
phf-attributes - 9.64 sec
Makefile.am | 3 +
rsvg-attributes.h | 163 ++++++
rsvg-base.c | 329 ++++++------
rsvg-cond.c | 44 +-
rsvg-filter.c | 1254 +++++++++++++++++++++++++++++++---------------
rsvg-handle.c | 12 +-
rsvg-paint-server.h | 12 -
rsvg-private.h | 38 +-
rsvg-styles.c | 556 +++++++++++---------
rsvg-styles.h | 6 +-
rsvg-text.c | 62 ++-
rust/Cargo.lock | 42 +-
rust/Cargo.toml | 5 +
rust/build.rs | 190 +++++++
rust/src/attributes.rs | 68 +++
rust/src/clip_path.rs | 13 +-
rust/src/cnode.rs | 4 +-
rust/src/gradient.rs | 225 ++++++---
rust/src/image.rs | 70 +--
rust/src/lib.rs | 15 +-
rust/src/marker.rs | 47 +-
rust/src/mask.rs | 43 +-
rust/src/node.rs | 13 +-
rust/src/paint_server.rs | 12 +-
rust/src/parsers.rs | 24 +
rust/src/pattern.rs | 114 +++--
rust/src/property_bag.rs | 340 ++++++++++---
rust/src/shapes.rs | 100 ++--
rust/src/stop.rs | 49 +-
rust/src/structure.rs | 106 ++--
30 files changed, 2710 insertions(+), 1249 deletions(-)
---
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]