Just an FYI that from WP 5.3 there are couple of functions to find and generate missing image sub-sizes, and the image meta is saved after each sub-size is generated.
For back-compat wp_generate_attachment_metadata() still returns the whole image meta array after all sub-sizes have been created (if the server doesn't run out of resources), but is not the best way to generate only missing image sub-sizes. See https://core.trac.wordpress.org/ticket/40439 and https://core.trac.wordpress.org/changeset/45538 (testing and suggestions welcome).