glthread: sort variables in marshal structures to pack them optimally