Skip to content

Let the caller say how long a page may be drawn for - #16

Merged
tannevaled merged 1 commit into
mainfrom
page-budget
Aug 27, 2026
Merged

Let the caller say how long a page may be drawn for#16
tannevaled merged 1 commit into
mainfrom
page-budget

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Options.MaxPixels bounds what comes out of a page. Nothing bounded the work of making it, so a caller drawing somebody else's file had no way to say how long it was prepared to wait.

Measured

Over 59 432 corpus pages at half again their own size: 1 131 were still being drawn after twenty seconds, and one figure took 273. Measuring this corpus once ended with every worker but one finished and the last grinding on a single page with 15.3 GB resident — a page that cannot be given up on is a page that can take a machine away from whoever was using it.

What it does

Options.MaxDuration. Zero means as long as it takes, which is what this did before, so nothing already written changes. When the time goes the page comes back as far as it got, with ErrTimedOut — deliberately not a blank: half a page is worth more than none to somebody scrolling, and the error says plainly that it is half.

The clock is looked at once every 256 operations, not on every one: asking the machine the time is dear beside drawing a line.

It costs nothing

Over 3 000 corpus pages with no budget set: 1:07 against 1:14 without the code at all — the difference is noise, and the wrong way round. Of the 2 991 pages both runs drew, not one hash differs.

100% statement coverage, go vet and gofmt clean, nine cross-compile targets.

Options.MaxPixels bounds what comes out of a page. Nothing bounded the work of
making it, so a caller drawing somebody else's file had no way to say how long
it was prepared to wait — and some pages take a very long time.

Measured over 59 432 corpus pages at half again their own size: 1 131 were
still being drawn after twenty seconds, and one figure took two hundred and
seventy-three. Two hours of measuring this corpus ended with every worker but
one finished and the last grinding on a single page with fifteen gigabytes
resident. A page that cannot be given up on is a page that can take a machine
away from whoever was using it.

Options.MaxDuration is how long it may have. Zero means as long as it takes,
which is what this did before there was anywhere to say otherwise, so nothing
already written changes. When the time goes, the page stops being drawn and
comes back as far as it got, with ErrTimedOut — deliberately not a blank, since
half a page is worth more than none to somebody scrolling, and the error says
plainly that it is half.

The clock is looked at once every 256 operations rather than on every one:
asking the machine the time is dear beside drawing a line. A page of a hundred
thousand operations therefore asks four hundred times.

It costs nothing. Over 3 000 corpus pages, with no budget set: 1:07 against
1:14 without the code at all — the difference is noise, and the wrong way
round. Of the 2 991 pages both runs drew, not one hash differs.
@tannevaled
tannevaled merged commit a4b3788 into main Aug 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant