Git Product home page Git Product logo

Comments (9)

wisskid avatar wisskid commented on July 24, 2024 1

I see. In that case, we can change it as follows:

	public function prependTemplateDir($new_template_dir, $is_config = false): void {
		$current_template_dirs = $is_config ? $this->config_dir : $this->template_dir;
		array_unshift($current_template_dirs, $new_template_dir);
		$this->setTemplateDir($current_template_dirs, $is_config);
	}

That would postpone the expensive call to _normalizeTemplateConfig up until the first load of a template. Correct?

from smarty.

wisskid avatar wisskid commented on July 24, 2024 1

@eileenmcnaughton you're welcome!

from smarty.

wisskid avatar wisskid commented on July 24, 2024

Could you elaborate on that second request? I'm afraid I don't understand what you mean.

from smarty.

wisskid avatar wisskid commented on July 24, 2024

And as for your first request, would you need something like this?

	public function prependTemplateDir($new_template_dir, $is_config = false): void {
		$current_template_dirs = $this->getTemplateDir(null, $is_config);
		array_unshift($current_template_dirs, $new_template_dir);
		$this->setTemplateDir($current_template_dirs, $is_config);
	}

from smarty.

totten avatar totten commented on July 24, 2024

@wisskid Yeah, that's the basic idea. Part of the reason for filing this is... that we recently found that's non-performant to repeatedly combine getTemplateDir() and setTemplateDir(). The going theory: each call to getTemplateDir() causes it to re-run normalization over all the paths.

For a small number of paths, that's fine. But it turns out - whenever one extension adds a path, it (re)normalizes n-many paths for all prior extensions. So it's basically O(n^2). Or here's the longer rationalization of that theory:

Screenshot from 2024-05-29 00-45-38

With a handful of extensions, no one notices. But for folks with a large number of extensions, it balloons.

So prependTemplateDirs() would probably want to bypass the (re)normalization that's built into getTemplateDir().

from smarty.

eileenmcnaughton avatar eileenmcnaughton commented on July 24, 2024

thanks for the quick reply - I was writing a response but seems Tim did first so I'll go with 'what he said' on the second.

On the first, I might be wrong on the second request but it's my understanding that if I have 2 bits of code that don't know about each other & each do

 $smarty->addTemplateDir('\srv\var\template');

Then the template will potentially be added and / or processed through _realPath() twice. I kinda get that it needs to be for symlinks but maybe there is a cheap check that can be done before going through all the expensive stuff

from smarty.

eileenmcnaughton avatar eileenmcnaughton commented on July 24, 2024

Yes that seems correct to me

from smarty.

wisskid avatar wisskid commented on July 24, 2024

I'll try to squeeze it in asap

from smarty.

eileenmcnaughton avatar eileenmcnaughton commented on July 24, 2024

thank you - you have been incredibly responsive!

from smarty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.