Best perform: filtering using instance and instance.pk

In these cases:

qs = MyModel.objects.filter(user=user)  #1

qs = MyModel.objects.filter(user_id=user.pk)  #2

Both results in the same queryset using a sql query like to WHERE "my_model"."user_id" = pk but if you use user=user as filter, internally search for the instance pk taking a little longer than user_id=user.pk. Maybe the logic to make sql queries for relationships is different that i think but without that “pk searching” in the 1st filter, the 2nd is a little faster?

There’s not going to be a “search”, it’s an object-attribute retrieval - effectively a dictionary lookup - which is one of the most highly optimized parts of core Python.

There is not going to be any practical difference between the two - not compared to everything else that needs to occur at that time. Worrying about that difference is wasted effort.