I believe what Jesus was referring to as ‘dogs’ and ‘swine’ were the Sanhedrin and the Pharisees of his day.
The ‘pearl and ‘that which is holy’ is the Gospel of the New Covenant. To preach the Gospel to the Sanhedrin and Pharisees of his time would have been not only a waste of the apostles’ and disciples’ time and efforts, but dangerous also, as Saul, later Saint Paul would clearly illustrate.
As Paul stated in the end of the Book of Acts:
24 Some were convinced by what he said, but others would not believe. 25 They disagreed among themselves and began to leave after Paul had made this final statement: The Holy Spirit spoke the truth to your ancestors when he said through Isaiah the prophet:
26
Go to this people and say,
You will be ever hearing but never understanding;
you will be ever seeing but never perceiving.
27
For this peoples heart has become calloused;
they hardly hear with their ears,
and they have closed their eyes.
Otherwise they might see with their eyes,
hear with their ears,
understand with their hearts
and turn, and I would heal them.[a]
28 Therefore I want you to know that Gods salvation has been sent to the Gentiles, and they will listen! [29] [b]
I’ve always thought that reference to “dogs” meant the Gentiles whom the Sanhedrin and Pharisees despised.