Skip to content
Snippets Groups Projects
Unverified Commit f8bf83b8 authored by Sean's avatar Sean Committed by GitHub
Browse files

Skip the final GC on shutdown to improve restart times (#10712)


Use `gc.freeze()` on exit to exclude all existing objects from the final GC.
In testing, this sped up shutdown by up to a few seconds.

`gc.freeze()` runs in constant time, so there is little chance of performance
regression.

Signed-off-by: default avatarSean Quah <seanq@element.io>
parent e2481dbe
Branches
Tags
No related merge requests found
Skip final GC at shutdown to improve restart performance.
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import atexit
import gc import gc
import logging import logging
import os import os
...@@ -403,6 +404,12 @@ async def start(hs: "HomeServer"): ...@@ -403,6 +404,12 @@ async def start(hs: "HomeServer"):
gc.collect() gc.collect()
gc.freeze() gc.freeze()
# Speed up shutdowns by freezing all allocated objects. This moves everything
# into the permanent generation and excludes them from the final GC.
# Unfortunately only works on Python 3.7
if platform.python_implementation() == "CPython" and sys.version_info >= (3, 7):
atexit.register(gc.freeze)
def setup_sentry(hs): def setup_sentry(hs):
"""Enable sentry integration, if enabled in configuration """Enable sentry integration, if enabled in configuration
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment