[SalesForce] Best way Optional warning message on page load

I have to show a message on top of a visual force on load page,if certain conditions are met.

I know 2 ways:

1) in the constructor:

    if (Querycondition){
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Warning,'warning description') 
    }

2) use action attribute of apex:page

<apex:page standardController="Account"  action="{!CheckValidation}">

and in the controller:

public PageReference CheckValidation(){     
            if (Querycondition){
                 ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Warning,'warning   description') 
            }
        return null;   
    } 

Is there some difference in terms of performance?

Thanks in advantage for any advice.

Best Answer

I can think of no reason why there should be a significant difference in performance.

Doing it in the constructor is the simplest approach. And you won't have to make a separate call in your tests to run that code.

The page action runs after the constructor has completed and has the capability of redirecting to another page which is not used here. So it seems a little over-complicated for this case. (It might be a useful approach if you want to use the same controller with multiple pages, where some need the check and others don't.)