Skip to content

Inefficiency in applying stylesheet #529

@bbshelper

Description

@bbshelper

If an epub's stylesheets contain a lot of class selectors (which is not rare) then current code can be terribly slow. Basically if there are m class selectors and n nodes, more than mn calls to LVCssSelectorRule::check() are made. Some optimization ideas:

  1. Hash class selectors (maybe also ID selectors) in the stylesheet. Given current class attr, we can skip most class selectors. Can be constructed during LVStyleSheet.push()?
  2. Cache various getAttributeValue() results in LVStyleSheet::apply(), so we don't repeatedly call that on the same node against different rules.
  3. ldomNode trades speed for space. On x64 there are 4 bytes padding that can be utilized, such as storing node ID. May be irrelevant if previous 2 items are implemented.

I test epubs with LoadDocument() and Render(). I've noticed that styles are applied in both calls. Why so?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions