There are 2 main factors that seem to lead to digital artifacts when creating JPEG images: Aliasing and Compression.
Example:
Converting a PNG with characters on it to a JPEG or placing vector images over a photograph, will result in pixelization on their edges. The antialiasing generally creates a kind of blur around them, but if the image is lossy compressed, part of the details are also lost, therefore the blur and the pixelization may become less noticeable.
Is this the right thing to do? I.e. since a lossless compression generates a highly detailed image, the artifacts resulting from aliasing will be more noticeable, so a balance may be found by using the right compression, although compromising the image quality.
Edit
I just saved this JPEG in mspaint (3.46KB):
Here's the same JPEG with maximum compression (lowest quality, 0.5KB):
Here's yet the same JPEG with 50% compression (notice the difference in size, 1.29KB):
The same 50% compression but saved as "progressive JPG", kept the original EXIF and XMP data, and "tried to save with original JPG quality" (you can notice that there are no grey pixels around, 2.96KB):
And finally the same as before with chroma subsampling disabled (same file size, 2.96KB):
mozjpeg
compressor has a special trick to produce less distortion on these kinds of images. (and it's more efficient in general than usual jpeg writers too.) did you try it? $\endgroup$