@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve performance when constructing custom fields for objects

Summary:
Ref T11404. This improves things by about 10%:

- Use `PhutilClassMapQuery`, which has slightly better caching.
- Do a little less work to generate pretty error messages.
- Make the "disabled" code a little faster (and sort of clearer, too?) by doing less fancy stuff.

These are pretty minor adjustments and not the sort of optimizations I'd make normally, but this code gets called ~100x (once per revision) and generates ~10 fields normally, so even small savings can amount to something.

(I also want to try to make `arc` faster in the next update, and improving Conduit performance helps with that.)

Test Plan: Ran `differential.revision.search`, saw cost drop from ~195ms to ~170ms locally.

Reviewers: yelirekim, chad

Reviewed By: chad

Maniphest Tasks: T11404

Differential Revision: https://secure.phabricator.com/D16355

+11 -11
+11 -11
src/infrastructure/customfield/field/PhabricatorCustomField.php
··· 112 112 $object, 113 113 array $options = array()) { 114 114 115 - $field_objects = id(new PhutilSymbolLoader()) 115 + $field_objects = id(new PhutilClassMapQuery()) 116 116 ->setAncestorClass($base_class) 117 - ->loadObjects(); 117 + ->execute(); 118 118 119 119 $fields = array(); 120 - $from_map = array(); 121 120 foreach ($field_objects as $field_object) { 122 - $current_class = get_class($field_object); 121 + $field_object = clone $field_object; 123 122 foreach ($field_object->createFields($object) as $field) { 124 123 $key = $field->getFieldKey(); 125 124 if (isset($fields[$key])) { ··· 127 126 pht( 128 127 "Both '%s' and '%s' define a custom field with ". 129 128 "field key '%s'. Field keys must be unique.", 130 - $from_map[$key], 131 - $current_class, 129 + get_class($fields[$key]), 130 + get_class($field), 132 131 $key)); 133 132 } 134 - $from_map[$key] = $current_class; 135 133 $fields[$key] = $field; 136 134 } 137 135 } ··· 146 144 147 145 if (empty($options['withDisabled'])) { 148 146 foreach ($fields as $key => $field) { 149 - $config = idx($spec, $key, array()) + array( 150 - 'disabled' => $field->shouldDisableByDefault(), 151 - ); 147 + if (isset($spec[$key]['disabled'])) { 148 + $is_disabled = $spec[$key]['disabled']; 149 + } else { 150 + $is_disabled = $field->shouldDisableByDefault(); 151 + } 152 152 153 - if (!empty($config['disabled'])) { 153 + if ($is_disabled) { 154 154 if ($field->canDisableField()) { 155 155 unset($fields[$key]); 156 156 }