MDL-36941 core_message: improved performance of helper::get_messages()