But not sure about your patch
since currently I have no idea how to verify its performance.
Maybe it should be pushed to master so that everyone can test it?
I think the performance requirements for 'project-name' are currently
rather modest: the name is only used when selecting the project (in
a custom config) and when generating some buffer names. For that, the new
logic should be fine.
With your feature, however, project-name could be called during redisplay,
and that might require better performance. So I thought you would test it
together with the patch for your feature request.
But I suppose if you're not working on it right this moment, I could push
the patch to emacs-29, and then we could refine the performance (if
necessary) on master.