Stange effect on CPU load

  • A customer encounters a strange effect while writing a report.

    Usecase

    Report is based on a template with header, footer and some small tables with addresses and the like, length is 3 pages.

    Spellcheck is disabled.

    Reproduced with a "typewriter" program typing the same block of text at constant speed.

    Does not happen on single-page documents.

    Attempt one

    User opens reports and starts typing on the first page. CPU goes up to 50% (1 core) and stays at 40..50% while typing

    Attempt two

    User opens report, scrolls down to the last page and up to 1st again, starts typing there. CPU stays between 10..20%

    Hypothesis

    Some off-screen elements are calculated or rendered repeatedly until they are made visible at last once by scrolling down

    Questions

    Are there any options or procedures which force a full-paint of the document after loading or ways to control rendering of offscreen content?

    Thanks Thomas

    • Offizieller Beitrag

    WPTools uses asynchon reformat and repaint. This has been implemented using PostMessage so reformat is not done immediately.

    Usually only the current paragraph is formatted but if a line break is created the current pages are formatted to make the change visible.

    The flag wpDisableSpeedReformat in FormatOptions modifies the formatting. If it is off (default) only the visible pages are reformatted.

    In any case - the CPU load should stop immediately after the typing. If this is not the case, maybe there is a timer running or a closed loop in a custom paint routine which also calls invalidate. In Firemonkey applications the blinking cursor also has this effect. Do you call ReformatAll? Usually that is not required, only in cases if there is no idle cycle between text creation and print or to display changes after low level routines, such as mail merge.

  • I found the culprit.

    Customer is using Logo in the header. As soon as a part of it is visible, CPU goes from 12% to 40%.

    With scrolling down and up again to the area I wanted to write, I pushed the logo out of the visible area.

    Image size is about 500kB.

    Are there options to manage display or rendering of images resulting in lower CPU-usage?

    • Offizieller Beitrag

    WPTools is not (yet) working with scaled down images internally, which would improve the speed (while reducing the output quality).

    But for a quick solution image display could be disabled (temporarily) using the OnTextObjectPaint event:

    Code
    procedure TForm1.WPRichText1TextObjectPaint(Sender: TObject;
      pobj: TWPTextObj; toCanvas: TCanvas; XRes, YRes, X, Y, W, H, BASE: Integer;
      PageRef: TWPVirtPage; Modes: TWPTextObjectPaintModes;
      const CanvasExtraAttr: TWPPaintExtraParams;
      var ContinueMode: TWPTextObjectPaintResult);
    begin
        if (pobj.IsImage) and  (Modes * [wpPaintObjDestIsPDF,wpPaintObjDestIsPrinter])=[] then
          ContinueMode := [wpObjPaintFrame];
    end;