WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#7363 closed enhancement (fixed)

Optimization for kses

Reported by: azaozz Owned by:
Milestone: 2.7 Priority: normal
Severity: normal Version: 2.6
Component: Optimization Keywords:
Focuses: Cc:

Description

Each time create_function() is called, it makes new global function taking up a bit of memory. It shouldn't be used where it may be called many times, like in loops or in functions that may be run many times.

It doesn't seem to be needed in preg_replace_callback() when there's already a callback function defined for it.

Attachments (2)

kses-create_function.patch (3.8 KB) - added by azaozz 6 years ago.
7363_2.patch (4.7 KB) - added by azaozz 6 years ago.
Reverts most of the previous changes and adds helper functions used as callbacks instead of create_function()

Download all attachments as: .zip

Change History (8)

comment:1 azaozz6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [8387]) kses - don't use create_function in preg_replace_callback. Fixes #7363.

comment:2 follow-up: westi6 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Did we really need to change the argument list for a load of functions that plugin authors might have been using?

Could we not store the anonymous functions in function level static variables or just make them un-anonymous while still preserving the old functions for plugin authors and getting the performance benifit?

comment:3 in reply to: ↑ 2 azaozz6 years ago

Replying to westi:

Did we really need to change the argument list for a load of functions that plugin authors might have been using?

The wp_kses_normalize_entities3() is new, just added few hours ago. The other two seems to have been made as callback functions for the specific preg_replace_callback(). Tried searching the Net for any place they've been used directly, but nothing came back.

However you're right that they may be used directly too, although they're a bit too specific/limited as callbacks.

azaozz6 years ago

Reverts most of the previous changes and adds helper functions used as callbacks instead of create_function()

comment:4 ryan6 years ago

No one should be using the _once* functions. I say go with whatever is fastest.

comment:5 westi6 years ago

Agreed. All callbacks should be treated as internal and not for use by plugins as if they were anonymous functions.

I'll update the phpDoc to mark them as internals.

comment:6 westi6 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [8410]) Mark kses callbacks as private. Fixes #7363.

Note: See TracTickets for help on using tickets.