Problem/Motivation

Url::fromRoute('', [], array('script' => &$scriptPath, 'prefix' => &$pathPrefix))->toString();

This is just wrong.

Proposed resolution

Try to fix it.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

wim leers’s picture

Title: Try to get rid of Url::fromRoute in system_js_settings_alter() » Try to get rid of Url::fromRoute() in system_js_settings_alter()
Assigned: Unassigned » nod_
Issue tags: +JavaScript

Assigning to @nod_ to get his feedback; he has tried to remove it in the past.

mpdonadio’s picture

I think one of the "get rid of url()" issues has some thoughts on this, too. I seem to recall spending some time on it w/o luck. I'll poke around.

dawehner’s picture

StatusFileSize
new2.7 KB

scriptPath was removed as part of #2362227: Replace all instances of current_path() so we are fine for that.
The other one could be fetched from the outbound path processors directly, maybe this is a bit better.

wim leers’s picture

Status: Active » Needs review

scriptPath was removed

Oh, hah! Yay :) One less thing to worry about :)

+++ b/core/modules/system/system.module
@@ -649,21 +649,19 @@ function system_js_settings_build(&$settings, AttachedAssetsInterface $assets) {
+  // Let output path processors set a prefix.
+  /** @var \Drupal\Core\PathProcessor\OutboundPathProcessorInterface $path_processor */
+  $path_processor = \Drupal::service('path_processor');
+  $path_processor->processOutbound('', $options);
+  $pathPrefix = $options['prefix'];

I like this idea a lot. Let's see if testbot likes it as much!

Status: Needs review » Needs work

The last submitted patch, 3: 2527846-3.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new2.71 KB
new644 bytes

Mh, that result means, yes, it likes it.

Status: Needs review » Needs work

The last submitted patch, 6: 2527846-6.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new2.71 KB
new764 bytes

Some test fixes.

Status: Needs review » Needs work

The last submitted patch, 8: 2527846-8.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new2.74 KB
new618 bytes

Maybe this?

Status: Needs review » Needs work

The last submitted patch, 10: 2527846-10.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new3.51 KB
new785 bytes

Finally this should fix the test failures.

Status: Needs review » Needs work

The last submitted patch, 12: 2527846-12.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new4.58 KB
new1.07 KB

Forgot to add a new file

dawehner’s picture

Issue tags: +Performance

.

nod_’s picture

Assigned: nod_ » Unassigned

I'm really not up to speed on how to get all that from the PHP so as long as it's gone and testbot is happy, I'm good with it.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC, very happy about the change.

dawehner’s picture

Just in case someone wants to, it would be interesting whether this also brings some performance benefit.

wim leers’s picture

Issue tags: -Performance

Profiled at /contact. Wall time delta is not to be trusted (too much variance); the other deltas are steady. Saves 54 function calls.

Before After Diff Diff%
Number of Function Calls 37,994 37,940 -54 -0.1%
Incl. Wall Time (microsec) 103,127 101,138 -1,989 -1.9%
Incl. MemUse (bytes) 17,847,816 17,844,856 -2,960 -0.0%
Incl. PeakMemUse (bytes) 17,981,776 17,979,016 -2,760 -0.0%
berdir’s picture

What about just comparing this function.. There shouldn't be a lot of variance then.

wim leers’s picture

I don't see the value of micro-profiling a function that's only called once per page load?

catch’s picture

More about interest than necessity I think - I posted a 'before' when I opened #2505055: Remove isFront from system_js_settings_alter().

berdir’s picture

I don't see the value of micro-profiling a function that's only called once
per page load?

Why would you not want to compare the actual function that is changing? There's no point in comparing the whole request if we know that nothing outside that function is changed.

And yes, I asked because I saw that issue that @catch created.

wim leers’s picture

Apologies, I didn't realize that it was taking 1.5 ms. Then micro profiling definitely makes sense.

dawehner’s picture

Issue tags: +Performance

Incl. Wall Time (microsec) 103,127 101,138 -1,989 -1.9%

This seems to be quite costly functions :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/system.module
@@ -648,21 +648,20 @@ function system_js_settings_build(&$settings, AttachedAssetsInterface $assets) {
-  $scriptPath = $request->getScriptName();
...
-    'scriptPath' => $scriptPath,

Why have we removed this? Ah because we don't need it since #2362227: Replace all instances of current_path() and it's an Drupal 8 only thing. I guess this is okay to remove without a CR.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

Didn't mean to change the status.

dawehner’s picture

Why have we removed this? Ah because we don't need it since #2362227: Replace all instances of current_path() and it's an Drupal 8 only thing. I guess this is okay to remove without a CR.

Yeah exactly.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed ca00412 on 8.0.x
    Issue #2527846 by dawehner, Wim Leers: Try to get rid of Url::fromRoute...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.