Improve pre-process template performance
Most of the files in template content doesn't have any operations but still are being processed each time the template is run.
Suggestion:
- pre-process the template on installing time to detect which files have operations defined and cache them
- those files to be processed each time the template is executed
- the other files will be processed in
copyOnlymode
Note: since in folder based templates the files may be changed, rescan should be done if the timestamp on the file has changed.
Tasks:
- [ ] https://github.com/dotnet/templating/issues/5788
Justification
As for distinguishing textual and binary files - it's normally not that easy (usually done by performing characters frequency analysis for various byte encoding lengths over a sample of the file and deciding whether the encoding seems to be match based on low occurence of nonprintable chars). But there are couple of simplifying options (we can combine them):
- We can call or borrow IsText functionality from VerifyTests/EmptyFiles
- Leveraging existing third party libraries solving this purpose: https://github.com/tylerlong/ude, https://github.com/superstrom/chardetsharp etc.
We might want to include simplified check (based on extensions only) to validation tasks. As such check is not 100% accurate, but very easy to implement, and during validation it's fine to have false positives. It would not be acceptable during instantiation (in another words: skipping files processing despite author did not opt-out VS informing the author during template authoring that we believe they might improve they template)
We might want to include simplified check (based on extensions only) to validation tasks. As such check is not 100% accurate, but very easy to implement, and during validation it's fine to have false positives. It would not be acceptable during instantiation (in another words: skipping files processing despite author did not opt-out VS informing the author during template authoring that we believe they might improve they template)
Added to https://github.com/dotnet/templating/issues/2623
I think one concern here is the line endings of text files that are marked for "copy only". If I remember correctly, even if the file needs no changes, template engine still updates the line endings of the text files depending on the environment. If it now starts to do a copy-only operation, line endings may stop matching the environment default.