cms icon indicating copy to clipboard operation
cms copied to clipboard

Bard fields augment multiple times with runtime Antlers parser

Open jacksleight opened this issue 3 years ago • 1 comments

Bug description

When using the runtime Antlers parser I'm seeing Bard fields being augmented/rendered multiple times, despite only being output once. I'm checking this by calling dump in the Statamic\Fieldtypes\Bard\Augmentor::convertToHtml method.

With the regex parser that method is only called once per output, with the runtime parser it's called three times.

Given that Bard fields can contain a large amount of content when used as page builders etc. this could have a significant performance impact.

How to reproduce

  1. Create a Bard field, add some content and output it in a template.
  2. Log the number of times the Bard Augmentor is run.

Logs

No response

Versions

Statamic 3.3.5 Pro Laravel 8.83.7 PHP 8.1.2

Installation

Starter Kit using via CLI

Antlers Parser

runtime (new)

Additional details

No response

jacksleight avatar Apr 07 '22 08:04 jacksleight

This is something I've been looking into with this work here: https://github.com/statamic/cms/pull/5783

Internally there are a number of places where a value may be resolved to determine what to do with the data:

  • An existence check: to help decide if something should be executed as a tag or variable
  • Checking for query builder instances to decide if they should be intercepted and ran through the query tag
  • Finally when resolving the value to actually produce output

I'll look into other improvements while that PR is reviewed/discussed 👍

JohnathonKoster avatar Apr 07 '22 11:04 JohnathonKoster