Before marriage is without doubt the best time. Quickest and least confusing for everyone involved.
If for some reason you can’t get there before you marry, go after you marry but before the I-94 expires. I had to do this because of covid-era SSA office policies. Note this route has a lower success rate, particularly if a name change is involved, but is 100% legitimate and many members on this site have got SSNs at this stage.
Filing AoS doesn’t affect SS application, but it is likely that by the time you have got all your evidence together for AoS, you’ve used too much time on the I-94 and SSN can’t be issued in time before I-94 expires.
After these two options, next is after receiving EAD, then GC. Good luck!
tl;dr : apply for SSN as soon as possible!!