diff --git a/src/Makefile.am b/src/Makefile.am
index a7bc4774ea3fb162a2b3af1ea825607659e34c6a..49bedc4f6dbc3415daefb456689a25c194325fe8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,7 +47,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
     sourceterms_struct.h statistics.h memswap.h cache.h runner_doiact_vec.h profiler.h \
     dump.h logger.h active.h timeline.h xmf.h gravity_properties.h gravity_derivatives.h \
     gravity_softened_derivatives.h vector_power.h collectgroup.h hydro_space.h sort_part.h \
-    chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h
+    chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h space_getsid.h
 
 # Common source files
 AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
@@ -132,7 +132,8 @@ nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h
                  chemistry/EAGLE/chemistry.h \
 		 chemistry/EAGLE/chemistry_io.h \
 		 chemistry/EAGLE/chemistry_struct.h\
-		 chemistry/EAGLE/chemistry_iact.h
+		 chemistry/EAGLE/chemistry_iact.h \
+     space_getsid.h
 
 
 # Sources and flags for regular library
diff --git a/src/cell.c b/src/cell.c
index ea036c97081e625c4e4ca2bb1d06cd9ea8251bd3..32c2a5b3b70105e9f3b1da20f59a285dbebc8530 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -60,6 +60,7 @@
 #include "minmax.h"
 #include "scheduler.h"
 #include "space.h"
+#include "space_getsid.h"
 #include "timers.h"
 
 /* Global variables. */
diff --git a/src/runner_doiact.h b/src/runner_doiact.h
index 2987d205e5005d4618c087bfe7f18a0b3c12fef5..4081e67b467cc14553973333865c8ef46c2fd99b 100644
--- a/src/runner_doiact.h
+++ b/src/runner_doiact.h
@@ -125,6 +125,9 @@
 #define _TIMER_DOPAIR_SUBSET(f) PASTE(timer_dopair_subset, f)
 #define TIMER_DOPAIR_SUBSET _TIMER_DOPAIR_SUBSET(FUNCTION)
 
+/* Local headers. */
+#include "space_getsid.h"
+
 /**
  * @brief Compute the interactions between a cell pair (non-symmetric case).
  *
diff --git a/src/scheduler.c b/src/scheduler.c
index 151304293749a29abe9bd9680d8f8f81bc845884..187ad7093badc6c53ccbb95377969550f9bffc67 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -48,6 +48,7 @@
 #include "queue.h"
 #include "sort_part.h"
 #include "space.h"
+#include "space_getsid.h"
 #include "task.h"
 #include "timers.h"
 #include "version.h"
diff --git a/src/space.c b/src/space.c
index 3da35b64a3f77b4de183c24188d3237d7680f621..93b7235d6d09d4fb0896487f811ec96bb3e2ff5c 100644
--- a/src/space.c
+++ b/src/space.c
@@ -103,52 +103,6 @@ struct index_data {
   int *ind;
 };
 
-/**
- * @brief Get the shift-id of the given pair of cells, swapping them
- *      if need be.
- *
- * @param s The space
- * @param ci Pointer to first #cell.
- * @param cj Pointer second #cell.
- * @param shift Vector from ci to cj.
- *
- * @return The shift ID and set shift, may or may not swap ci and cj.
- */
-int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
-                 double *shift) {
-
-  /* Get the relative distance between the pairs, wrapping. */
-  const int periodic = s->periodic;
-  double dx[3];
-  for (int k = 0; k < 3; k++) {
-    dx[k] = (*cj)->loc[k] - (*ci)->loc[k];
-    if (periodic && dx[k] < -s->dim[k] / 2)
-      shift[k] = s->dim[k];
-    else if (periodic && dx[k] > s->dim[k] / 2)
-      shift[k] = -s->dim[k];
-    else
-      shift[k] = 0.0;
-    dx[k] += shift[k];
-  }
-
-  /* Get the sorting index. */
-  int sid = 0;
-  for (int k = 0; k < 3; k++)
-    sid = 3 * sid + ((dx[k] < 0.0) ? 0 : ((dx[k] > 0.0) ? 2 : 1));
-
-  /* Switch the cells around? */
-  if (runner_flip[sid]) {
-    struct cell *temp = *ci;
-    *ci = *cj;
-    *cj = temp;
-    for (int k = 0; k < 3; k++) shift[k] = -shift[k];
-  }
-  sid = sortlistID[sid];
-
-  /* Return the sort ID. */
-  return sid;
-}
-
 /**
  * @brief Recursively dismantle a cell tree.
  *
diff --git a/src/space.h b/src/space.h
index 76d9369db22740440831fe13eb4d57672e4f9951..5f7f910b585651068996eb548423ffbe86507ed2 100644
--- a/src/space.h
+++ b/src/space.h
@@ -180,8 +180,6 @@ void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max,
 void space_sparts_sort(struct space *s, int *ind, size_t N, int min, int max,
                        int verbose);
 void space_getcells(struct space *s, int nr_cells, struct cell **cells);
-int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
-                 double *shift);
 void space_init(struct space *s, const struct swift_params *params,
                 const struct cosmology *cosmo, double dim[3],
                 struct part *parts, struct gpart *gparts, struct spart *sparts,
diff --git a/src/space_getsid.h b/src/space_getsid.h
new file mode 100644
index 0000000000000000000000000000000000000000..64fcbf1e37f99afa93e2c65fd7659600249bea19
--- /dev/null
+++ b/src/space_getsid.h
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * This file is part of SWIFT.
+ * Copyright (c) 2018 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ ******************************************************************************/
+#ifndef SWIFT_SPACE_GETSID_H
+#define SWIFT_SPACE_GETSID_H
+
+/* Config parameters. */
+#include "../config.h"
+
+/* Some standard headers. */
+#include <stddef.h>
+
+/* Includes. */
+#include "cell.h"
+#include "runner.h"
+#include "space.h"
+
+/**
+ * @brief Get the shift-id of the given pair of cells, swapping them
+ *      if need be.
+ *
+ * @param s The space
+ * @param ci Pointer to first #cell.
+ * @param cj Pointer second #cell.
+ * @param shift Vector from ci to cj.
+ *
+ * @return The shift ID and set shift, may or may not swap ci and cj.
+ */
+__attribute__((always_inline)) INLINE static int space_getsid(struct space *s,
+                                                              struct cell **ci,
+                                                              struct cell **cj,
+                                                              double *shift) {
+
+  /* Get the relative distance between the pairs, wrapping. */
+  const int periodic = s->periodic;
+  double dx[3];
+  for (int k = 0; k < 3; k++) {
+    dx[k] = (*cj)->loc[k] - (*ci)->loc[k];
+    if (periodic && dx[k] < -s->dim[k] / 2)
+      shift[k] = s->dim[k];
+    else if (periodic && dx[k] > s->dim[k] / 2)
+      shift[k] = -s->dim[k];
+    else
+      shift[k] = 0.0;
+    dx[k] += shift[k];
+  }
+
+  /* Get the sorting index. */
+  int sid = 0;
+  for (int k = 0; k < 3; k++)
+    sid = 3 * sid + ((dx[k] < 0.0) ? 0 : ((dx[k] > 0.0) ? 2 : 1));
+
+  /* Switch the cells around? */
+  if (runner_flip[sid]) {
+    struct cell *temp = *ci;
+    *ci = *cj;
+    *cj = temp;
+    for (int k = 0; k < 3; k++) shift[k] = -shift[k];
+  }
+  sid = sortlistID[sid];
+
+  /* Return the sort ID. */
+  return sid;
+}
+
+#endif /* SWIFT_SPACE_GETSID_H */