Reza Rad discusses the performance implications of query folding in M:
I can’t start talking about the issue without explaining what Query Folding is, so let’s start with that. Query Folding means translating Power Query (M) transformations into native query language of the data source (for example T-SQL). In other words; when you run Power Query script on top of a SQL Server database, query folding will translate the M script into T-SQL statements, and fetch the final results.
Click through for more details. The advice here sounds pretty similar to what we get for optimizing Integration Services: push as much of the heavy lifting onto well-optimized source queries as possible, particularly when it comes to filtering out rows.