Optimizations:

1) Keep a rectangle updated per-screen rather than regenerate each time
2) Strip palette info when putting pixels into rectangles rather than
   during scaling
3) Tighten up the screen locks a bit
4) Don't require a full resend of both screens on an update request
5) Only force a redraw for cursor movement when the cursor is visible
   (And force it whenever the cursor changes)
6) Avoid doubles in interpolation
7) Heavily optimize interpolate_height()
   interpolate_width() likely doesn't need it because it's generally not
   used and also it reads from the next pixel in memory making the
   prefetchers job easier.
8) Fix some memory-leak-on-error issues
9) For ARGB8 XImages, manipulate the data directly rather than through
   XPutPixel()

At this point, the scaling and X11 output time is heavily dominated by
cache misses.  The only really effective way to reduce this hit is to
spread the work across all the L3 caches in the system or move it into
the GPU.

With the latest updates, at the SyncTERM menu, over 90% of the time is
spent in the rendering pipeline, and over 90% of that time is spent
thrashing the caches... the only real easy win left is vectorizing, but
that's highly compiler specific.

To that end, I've switched to -O3 for release builds.  There was a comment
that -finline-functions broke Baja "badly", but that's clearly false since
-f-inline-functions has been part of -O2 for quite a while now, and Baja
doesn't seem any more broken that it ever was.
14 jobs for master in 8 minutes and 49 seconds (queued for 11 seconds)
Status Job ID Name Coverage
  Build
failed #24426
FreeBSD
jsdoor-freebsd

00:06:51

failed #24427
Linux
jsdoor-linux

00:05:09

failed #24429
FreeBSD
jsdoor-windows

00:02:31

failed #24421
FreeBSD
sbbs-freebsd

00:08:47

failed #24416
Linux
sbbs-linux

00:06:54

passed #24419
Windows
sbbs-windows

00:05:44

passed #24428
FreeBSD
sexpots-freebsd

00:00:46

passed #24417
Linux
sexpots-linux

00:00:19

passed #24420
Windows
sexpots-windows

00:00:34

failed #24424
FreeBSD
syncdraw-freebsd

00:01:03

failed #24425
Linux
syncdraw-linux

00:00:15

failed #24422
FreeBSD
syncterm-freebsd

00:01:01

failed #24418
Linux
syncterm-linux

00:00:27

failed #24423
FreeBSD
syncterm-windows

00:01:11

 
Name Stage Failure
failed
sbbs-freebsd Build
scale.c:869:2: warning: declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
scale.c:869:10: error: use of undeclared identifier 'stderr'
fprintf(stderr, "Allocation failure in interpolate_height()!");
^
2 warnings and 1 error generated.
gmake[1]: *** [../build/Common.gmake:462: clang.freebsd.amd64.obj.release-mt/scale.o] Error 1
gmake[1]: Leaving directory '/var/tmp/gitlab_runner/builds/TkL89aUh/0/main/sbbs/src/conio'
gmake: *** [/var/tmp/gitlab_runner/builds/TkL89aUh/0/main/sbbs/src/sbbs3/../build/Common.gmake:509: ciolib-mt] Error 2
ERROR: Job failed: exit status 1
failed
jsdoor-freebsd Build
        fprintf(stderr, "Allocation failure in interpolate_height()!");
^
2 warnings and 1 error generated.
gmake[2]: *** [../build/Common.gmake:462: clang.freebsd.amd64.obj.release-mt/scale.o] Error 1
gmake[2]: Leaving directory '/var/tmp/gitlab_runner/builds/TkL89aUh/4/main/sbbs/src/conio'
gmake[1]: *** [../build/Common.gmake:509: ciolib-mt] Error 2
gmake[1]: Leaving directory '/var/tmp/gitlab_runner/builds/TkL89aUh/4/main/sbbs/src/uifc'
gmake: *** [/var/tmp/gitlab_runner/builds/TkL89aUh/4/main/sbbs/src/sbbs3/../build/Common.gmake:517: uifc-mt] Error 2
ERROR: Job failed: exit status 1
failed
sbbs-linux Build
  fprintf(stderr, "Allocation failure in interpolate_height()!");
^~~~~~
scale.c:869:10: note: ‘stderr’ is defined in header ‘<stdio.h>’; did you forget to ‘#include <stdio.h>’?
scale.c:869:10: note: each undeclared identifier is reported only once for each function it appears in
make[1]: *** [../build/Common.gmake:462: gcc.linux.x64.obj.release-mt/scale.o] Error 1
make[1]: Leaving directory '/home/gitlab-runner/builds/vLEE6HYB/1/main/sbbs/src/conio'
make: *** [/home/gitlab-runner/builds/vLEE6HYB/1/main/sbbs/src/sbbs3/../build/Common.gmake:509: ciolib-mt] Error 2
Cleaning up file based variables
ERROR: Job failed: exit status 1
failed
jsdoor-linux Build
scale.c:869:10: note: ‘stderr’ is defined in header ‘<stdio.h>’; did you forget to ‘#include <stdio.h>’?
scale.c:869:10: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [../build/Common.gmake:462: gcc.linux.x64.obj.release-mt/scale.o] Error 1
make[2]: Leaving directory '/home/gitlab-runner/builds/vLEE6HYB/0/main/sbbs/src/conio'
make[1]: *** [../build/Common.gmake:509: ciolib-mt] Error 2
make[1]: Leaving directory '/home/gitlab-runner/builds/vLEE6HYB/0/main/sbbs/src/uifc'
make: *** [/home/gitlab-runner/builds/vLEE6HYB/0/main/sbbs/src/sbbs3/../build/Common.gmake:517: uifc-mt] Error 2
Cleaning up file based variables
ERROR: Job failed: exit status 1
failed
jsdoor-windows Build
  fprintf(stderr, "Allocation failure in interpolate_height()!");
^
scale.c:869:10: note: each undeclared identifier is reported only once for each function it appears in
gmake[2]: *** [../build/Common.gmake:462: gcc.win32.amd64.obj.release-mt/scale.o] Error 1
gmake[2]: Leaving directory '/var/tmp/gitlab_runner/builds/TkL89aUh/5/main/sbbs/src/conio'
gmake[1]: *** [../build/Common.gmake:509: ciolib-mt] Error 2
gmake[1]: Leaving directory '/var/tmp/gitlab_runner/builds/TkL89aUh/5/main/sbbs/src/uifc'
gmake: *** [/var/tmp/gitlab_runner/builds/TkL89aUh/5/main/sbbs/src/sbbs3/../build/Common.gmake:517: uifc-mt] Error 2
ERROR: Job failed: exit status 1
failed
syncterm-windows Build
scale.c:869:2: warning: incompatible implicit declaration of built-in function 'fprintf' [enabled by default]
scale.c:869:10: error: 'stderr' undeclared (first use in this function)
fprintf(stderr, "Allocation failure in interpolate_height()!");
^
scale.c:869:10: note: each undeclared identifier is reported only once for each function it appears in
gmake[1]: *** [../build/Common.gmake:462: gcc.win32.amd64.obj.release-mt/scale.o] Error 1
gmake[1]: Leaving directory '/var/tmp/gitlab_runner/builds/TkL89aUh/2/main/sbbs/src/conio'
gmake: *** [../build/Common.gmake:509: ciolib-mt] Error 2
ERROR: Job failed: exit status 1
failed
syncdraw-freebsd Build
scale.c:869:2: warning: declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
scale.c:869:10: error: use of undeclared identifier 'stderr'
fprintf(stderr, "Allocation failure in interpolate_height()!");
^
2 warnings and 1 error generated.
gmake[1]: *** [../build/Common.gmake:462: clang.freebsd.amd64.obj.release-mt/scale.o] Error 1
gmake[1]: Leaving directory '/var/tmp/gitlab_runner/builds/TkL89aUh/3/main/sbbs/src/conio'
gmake: *** [../build/Common.gmake:509: ciolib-mt] Error 2
ERROR: Job failed: exit status 1
failed
syncterm-freebsd Build
scale.c:869:2: warning: declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h> [-Wbuiltin-requires-header]
scale.c:869:10: error: use of undeclared identifier 'stderr'
fprintf(stderr, "Allocation failure in interpolate_height()!");
^
2 warnings and 1 error generated.
gmake[1]: *** [../build/Common.gmake:462: clang.freebsd.amd64.obj.release-mt/scale.o] Error 1
gmake[1]: Leaving directory '/var/tmp/gitlab_runner/builds/TkL89aUh/1/main/sbbs/src/conio'
gmake: *** [../build/Common.gmake:509: ciolib-mt] Error 2
ERROR: Job failed: exit status 1
failed
syncterm-linux Build
  fprintf(stderr, "Allocation failure in interpolate_height()!");
^~~~~~
scale.c:869:10: note: ‘stderr’ is defined in header ‘<stdio.h>’; did you forget to ‘#include <stdio.h>’?
scale.c:869:10: note: each undeclared identifier is reported only once for each function it appears in
make[1]: *** [../build/Common.gmake:462: gcc.linux.x64.obj.release-mt/scale.o] Error 1
make[1]: Leaving directory '/home/gitlab-runner/builds/vLEE6HYB/3/main/sbbs/src/conio'
make: *** [../build/Common.gmake:509: ciolib-mt] Error 2
Cleaning up file based variables
ERROR: Job failed: exit status 1
failed
syncdraw-linux Build
x_events.c: In function ‘x11_event’:
x_events.c:716:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
716 | write(key_pipe[1], &key, 2);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
x_events.c:977:10: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
977 | write(key_pipe[1], &ch, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
x_events.c:1160:8: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
1160 | write(key_pipe[1], &key, (scan&0xff)?1:2);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~