diff --git a/src/modules/_Stdio/file.c b/src/modules/_Stdio/file.c
index 40378e8618e39953ad8a92a1836a658ad77f6caa..9de978539cdae586ace18739d5c57144dde223ca 100644
--- a/src/modules/_Stdio/file.c
+++ b/src/modules/_Stdio/file.c
@@ -145,6 +145,14 @@
 #define UNIX_SOCKET_CAPABILITIES (fd_INTERPROCESSABLE | fd_BIDIRECTIONAL | fd_CAN_NONBLOCK | fd_CAN_SHUTDOWN | fd_SEND_FD)
 #endif
 
+/*
+ * gcc with -O3 generates very bloated code for the functions in this file. One rather extreme example
+ * is file_open, which ends up having 32 call sites of open(2).
+ */
+#ifdef __GNUC__
+#pragma GCC optimize "-Os"
+#endif
+
 /* #define SOCKETPAIR_DEBUG */
 
 struct program *file_program;