Make WordPress Core


Ignore:
Timestamp:
03/12/2024 02:25:30 PM (20 months ago)
Author:
audrasjb
Message:

HTML API: Defer applying attribute updates until necessary.

When making repeated updates to a document, the Tag Processor will end
up copying the entire document once for every update. This can lead to
catastrophic behavior in the worse case.

However, when batch-applying updates it's able to copy chunks of the
document in one thread and only end up copying the entire document once
for the entire batch.

Previously the Tag Processor has been eagerly applying udpates, but in
this patch it defers applying those updates as long as is possible.
Developed in https://github.com/WordPress/wordpress-develop/pull/6120
Discussed in https://core.trac.wordpress.org/ticket/60697

Follow-up to [55706], [56941], [57348].

Reviewed by swissspidy.
Merges [57805] to the to the 6.5 branch.

Props dmsnell, bernhard-reiter, jonsurrell, westonruter.
Fixes #60697.

Location:
branches/6.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.5

  • branches/6.5/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php

    r57527 r57815  
    294294    /**
    295295     * @ticket 56299
     296     * @ticket 60697
    296297     *
    297298     * @covers WP_HTML_Tag_Processor::seek
     
    300301        $processor = new WP_HTML_Tag_Processor( '<div>First</div><div>Second</div>' );
    301302        $processor->next_tag();
    302         $processor->set_bookmark( 'first' );
    303         $processor->next_tag();
     303        $processor->set_attribute( 'id', 'one' );
     304        $processor->set_bookmark( 'first' );
     305        $processor->next_tag();
     306        $processor->set_attribute( 'id', 'two' );
    304307        $processor->add_class( 'second' );
    305308
     
    308311
    309312        $this->assertSame(
    310             '<div class="first">First</div><div class="second">Second</div>',
     313            'one',
     314            $processor->get_attribute( 'id' ),
     315            'Should have remembered attribute change from before the seek.'
     316        );
     317
     318        $this->assertSame(
     319            '<div class="first" id="one">First</div><div class="second" id="two">Second</div>',
    311320            $processor->get_updated_html(),
    312321            'The bookmark was updated incorrectly in response to HTML markup updates'
Note: See TracChangeset for help on using the changeset viewer.