Index: modules/field/modules/field_sql_storage/field_sql_storage.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/field_sql_storage/field_sql_storage.install,v
retrieving revision 1.10
diff -u -p -r1.10 field_sql_storage.install
--- modules/field/modules/field_sql_storage/field_sql_storage.install	29 Sep 2010 19:46:40 -0000	1.10
+++ modules/field/modules/field_sql_storage/field_sql_storage.install	10 Dec 2010 17:40:51 -0000
@@ -122,5 +122,15 @@ function field_sql_storage_update_7000()
 }
 
 /**
+ * Remove 'field_sql_storage_ENTITYTYPE_etid' system variables.
+ */
+function field_sql_storage_update_7001() {
+  $types = db_query('SELECT type, etid FROM {field_config_entity_type}')->fetchAllKeyed();
+  foreach ($types as $entity_type => $etid) {
+    variable_del('field_sql_storage_' . $entity_type . '_etid');
+  }
+}
+
+/**
  * @} End of "defgroup field-updates-6.x-to-7.x"
  */
Index: modules/field/modules/field_sql_storage/field_sql_storage.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/field_sql_storage/field_sql_storage.module,v
retrieving revision 1.56
diff -u -p -r1.56 field_sql_storage.module
--- modules/field/modules/field_sql_storage/field_sql_storage.module	6 Oct 2010 13:57:47 -0000	1.56
+++ modules/field/modules/field_sql_storage/field_sql_storage.module	10 Dec 2010 17:44:41 -0000
@@ -96,21 +96,44 @@ function _field_sql_storage_indexname($n
 }
 
 /**
- * Retrieve or assign an entity type id for an entity type.
+ * Retrieve or assign an entity type ID for an entity type.
  *
  * @param $entity_type
- *   The entity type, such as 'node' or 'user'.
- * @return
- *   The entity type id.
+ *   (optional) The entity type, such as 'node' or 'user'.
  *
+ * @return
+ *   The entity type ID, if $entity_type as passed, or an associative array
+ *   containing the entire type-ID mapping.
  */
-function _field_sql_storage_etid($entity_type) {
-  $etid = variable_get('field_sql_storage_' . $entity_type . '_etid', NULL);
-  if (!isset($etid)) {
-    $etid = db_insert('field_config_entity_type')->fields(array('type' => $entity_type))->execute();
-    variable_set('field_sql_storage_' . $entity_type . '_etid', $etid);
+function _field_sql_storage_etid($entity_type = NULL) {
+  $types = &drupal_static(__FUNCTION__);
+  $write_cache = FALSE;
+
+  if (!isset($types)) {
+    if ($cache = cache_get('entity_type_ids', 'cache_bootstrap')) {
+      $types = $cache->data;
+    }
+    else {
+      $types = db_query('SELECT type, etid FROM {field_config_entity_type}')->fetchAllKeyed();
+      $write_cache = TRUE;
+    }
+  }
+
+  if (isset($entity_type) && !isset($types[$entity_type])) {
+    $types[$entity_type] = db_insert('field_config_entity_type')
+      ->fields(array('type' => $entity_type))
+      ->execute();
+    $write_cache = TRUE;
+  }
+
+  if ($write_cache) {
+    cache_set('entity_type_ids', $types, 'cache_bootstrap');
+  }
+
+  if (isset($entity_type)) {
+    return $types[$entity_type];
   }
-  return $etid;
+  return $types;
 }
 
 /**
