pdf-raku / PDF-Content-raku

Basic PDF content editing and rendering support, including text, images, fonts and general graphics
Artistic License 2.0
2 stars 3 forks source link

Threading support #14

Closed dwarring closed 2 years ago

dwarring commented 2 years ago

The most obvious unit of parallilism, is a page or a set of pages. For example when rendering a book. It may make sense to break it down into chapters which are separated by page breaks. Within the chapters the text flow between pages requires them to be constructed in sequence.

The major shared resource between pages is fonts. Fonts need to be shared between pages and the adapted encoding and glyph detection for subsetting needs to be thread-safe.

Fonts is likely to be be where much of the work is and there needs to be some locking somewhere. Either (i) fine-grained locking in the font encoders or more coarse grained (ii) only allowing a font to be rendering once on any given font.

(i) will impact both core fonts and PDF::Font::Loader, which will need to have locking support in all its encoders (ii) is much simpler, but may result in bottlenecks if the rendering is text (rather than image) intensive and a common font is being used across threads.

dwarring commented 2 years ago

Ended up locking at the encode/decode level. Locks are at most held while a line of text is being encoded.