• Resolved matsa24

    (@matsa24)


    Hello!

    I use the filter
    "the_seo_framework_title_from_custom_field"
    to add the last date of the post change to the title.

    But here’s what I noticed. When using this filter, the function that binds to it is called several times (namely, 6 times), although I am waiting for only one.

    Why is this happening?

    Also, I noticed that the function
    "public function get_filtered_raw_custom_field_title( $args )"
    in the file
    "generate-title.class.php"
    also called 6 times.

    Is this a normal job?
    Does this increase the loading time of the site?

    • This topic was modified 3 years, 6 months ago by matsa24.
    • This topic was modified 3 years, 6 months ago by matsa24.
    • This topic was modified 3 years, 6 months ago by matsa24.
Viewing 1 replies (of 1 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    TSF currently has about 1 bug per 7 000 software lines of code (industry-standard is 1 per 65). So, you can assume almost everything is a ‘normal job.’

    The function in question runs multiple times to generate a meta title, Open Graph title, Twitter title, etc.

    Each call increases load time by about 0.0000005274 seconds on PHP 7.4.
    Here you can find the calculations: https://i.imgur.com/UoGoX7e.png.

    I constantly optimize opcode calls, so you need not worry about these things. In this case, we use apply_filters_ref_array instead of apply_filters to circumvent a func_get_args() call when no reactors are hooked on the filter.

    If you care about performance, it’s your duty not to create expensive queries in the filter. But, if you must, you can utilize memoization using the static keyword (example). For the get_filtered_raw_custom_field_title() method of TSF, I did not use that and instead traded about 0.000003 seconds of load-time for greater filtering flexibility.

Viewing 1 replies (of 1 total)
  • The topic ‘The filter function is called 6 times’ is closed to new replies.