[Samsung Galaxy S8 & S8+ Cross Device Development] foobar66:
You don't even need to do that: cache, dalvik, system are automatically cleaned at the beginning of the install process ;) When you do an install the following happens:

ui_print("- Removing files from /cache, dalvik, /system");
delete_recursive("/cache");
delete_recursive("/data/dalvik-cache");
delete("/data/LS00settings.touch");
delete_recursive("/system");

- indeed root apps seem to have lost root rights (I always enable the automatic root grant); I had not noticed this before (might be because Magisk writes some data in the /cache partition ... but I don't really know)

- a fresh install removes a file called /data/LS00settings.touch (see code above); this will cause the "one-off" settings to run after an install of a new release; these settings will reset the tile QS tile layout (see script /system/etc/services.d/LS99settingsonce). To avoid this to happen; do the install and then (while still in TWRP):

> adb shell

$ touch /data/LS00settings.touch

$ reboot

Then your tile layout should remain the same as well as lockscreen messages.

It is bit of a compromise ... somehow the "one-off" settings need to run once ... so they are ran 1st boot after an upgrade. The following are applied:

$CMD settings put global Window_animation_scale 0
$CMD settings put global adb_enabled 1
$CMD settings put global animator_duration_scale 0
$CMD settings put global assisted_gps_enabled 1
$CMD settings put global auto_time 1
$CMD settings put global auto_time_zone 1
$CMD settings put global brightness_auto 1
$CMD settings put global brightness_on_top 1
$CMD settings put global debug_app null
$CMD settings put global development_settings_enabled 1
$CMD settings put global device_idle_constants "inactive_to=60000,sensing_to=0,locating_to=0,locating_accuracy=10000,motion_inactive_to=0,idle_after
_inactive_to=0,idle_pending_to=120000,max_idle_pending_to=120000,idle_pending_factor=2,idle_to=1800000,max_idle_to=21600000,idle_factor=2,min_time_t
o_alarm=3600000,max_temp_app_whitelist_duration=300000,mms_temp_app_whitelist_duration=60000,sms_temp_app_whitelist_duration=20000"
$CMD settings put global display_size_forced 1440,2960
$CMD settings put global heads_up_notifications_enabled 0
$CMD settings put global lockscreen_aod_servicebox_page servicebox_clock
$CMD settings put global mobile_data_always_on 0
$CMD settings put global navigationbar_force_touch_enable 0
$CMD settings put global netstats_enabled 0
$CMD settings put global online_manual_url 0
$CMD settings put global ota_disable_automatic_update 1
$CMD settings put global overlay_display_devices null
$CMD settings put global transition_animation_scale 0
$CMD settings put global wait_for_debugger 0
$CMD settings put global wifi_networks_available_notification_on 0
$CMD settings put global wifi_scan_always_enabled 0
$CMD settings put global window_animation_scale 0

$CMD settings put secure brightness_auto 1
$CMD settings put secure brightness_on_top 1
$CMD settings put secure default_display_density_forced 640
$CMD settings put secure default_display_size_forced 1440,2960
$CMD settings put secure development_settings_enabled 1
$CMD settings put secure dialer_default_application com.google.android.dialer
$CMD settings put secure disabled_print_services "com.android.bips/.BuiltInPrintService"
$CMD settings put secure display_density_forced 640
$CMD settings put secure first_enter_wifisetupwizard 1
$CMD settings put secure install_non_market_apps 1
$CMD settings put secure lock_screen_allow_private_notifications 1
$CMD settings put secure lock_screen_owner_info_enabled 0
$CMD settings put secure lock_screen_show_notifications 1
$CMD settings put secure notification_badging 0
$CMD settings put secure qs_tile_column 5
$CMD settings put secure qs_tile_layout 5
$CMD settings put secure screensaver_enabled 0
$CMD settings put secure sms_default_application com.google.android.apps.messaging
$CMD settings put secure sysui_qqs_count 5
$CMD settings put secure sysui_qs_tiles "Wifi,Bluetooth,MobileData,Location,SoundMode,AirplaneMode,Flashlight,BlueLightFilter,custom(com.samsung.and
roid.app.aodservice/.settings.AODTileService),Dnd,custom(com.android.nfc/com.samsung.android.nfc.quicktile.NfcTile),custom(com.android.settings/com.
samsung.android.settings.qstile.PowerSavingTile),Hotspot,custom(com.samsung.android.lool/com.samsung.android.sm.ui.booster.PerformanceTile),custom(p
rojekt.substratum/.services.tiles.SubstratumTile)"
$CMD settings put secure tts_default_synth com.google.android.tts

$CMD settings put system access_control_enabled 0
$CMD settings put system adaptive_fast_charging 1
$CMD settings put system add_info_music_control 0
$CMD settings put system aod_show_state 0
$CMD settings put system device_visibility_enabled 0
$CMD settings put system dim_screen 1
$CMD settings put system direct_share 0
$CMD settings put system display_battery_percentage 1
$CMD settings put system easy_mode_switch 1
$CMD settings put system fingerprint_gesture_quick 1
$CMD settings put system fingerprint_guide_shown 0
$CMD settings put system haptic_feedback_enabled 1
$CMD settings put system hdr_effect 1
$CMD settings put system lock_application_shortcut "0;com.google.android.apps.messaging/com.google.android.apps.messaging.ui.ConversationListActivit
y;0;com.sec.android.app.camera/com.sec.android.app.camera.Camera;"
$CMD settings put system lockscreen_ripple_effect 0
$CMD settings put system lockscreen_sounds_enabled 1
$CMD settings put system motion_merged_mute_pause 0
$CMD settings put system motion_overturn 0
$CMD settings put system motion_pick_up 0
$CMD settings put system motion_pick_up_to_call_out 0
$CMD settings put system multi_window_enabled 0
$CMD settings put system nearby_scanning_enabled 0
$CMD settings put system people_stripe 0
$CMD settings put system samsung_pay 0
$CMD settings put system screen_mode_automatic_setting 0
$CMD settings put system screen_mode_setting 2
$CMD settings put system screen_off_po
$CMD settings put system sec_display_preset_index 2
$CMD settings put system sec_display_temperature_custom 0
$CMD settings put system send_security_reports 0
$CMD settings put system sip_key_feedback_sound 0
$CMD settings put system sip_key_feedback_vibration 0
$CMD settings put system support_split_sound 0
$CMD settings put system surface_palm_touch 0
$CMD settings put system transition_animation_scale 0
$CMD settings put system vibrate_when_ringing 1
$CMD settings put system window_animation_scale 0
$CMD settings put system wireless_fast_charging 1
$CMD settings put system screen_off_timeout 300000
$CMD settings put system screen_off_timeout_rollback 300000

It is the sysui_qs_tiles setting which causes your tiles to have changed.

I realize some of those settings (by default) may not be to everyone's liking ... all of them can be changed in the settings app. It's a choice (my choice). Note that some of them are really essential for the rom, for example: $CMD settings put secure dialer_default_application com.google.android.dialer, that enables the google dialer.