optimize-AtProcExit_Buffers-1.patch

text/x-diff

Filename: optimize-AtProcExit_Buffers-1.patch
Type: text/x-diff
Part: 0
Message: Re: profiling connection overhead

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/storage/buffer/bufmgr.c 10 1
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 54c7109..03593fd 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -1665,11 +1665,20 @@ static void
 AtProcExit_Buffers(int code, Datum arg)
 {
 	int			i;
+	int		   *ptr;
+	int		   *end;
 
 	AbortBufferIO();
 	UnlockBuffers();
 
-	for (i = 0; i < NBuffers; i++)
+	/* Fast search for the first non-zero entry in PrivateRefCount */
+	end = (int *) &PrivateRefCount[NBuffers - 1];
+	ptr = (int *) PrivateRefCount;
+	while(ptr < end && *ptr == 0)
+		ptr++;
+	i = ((int32 *) ptr) - PrivateRefCount;
+
+	for (;i < NBuffers; i++)
 	{
 		if (PrivateRefCount[i] != 0)
 		{