@@ -391,4 +391,27 @@ use cases.
391391
392392## Symbol-based Renamer
393393
394- (TODO: Explain how the symbol-based renamer works and why ` SymbolFinder.FindReferencesAsync ` is not used.)
394+ The renamer exists as ` NameUtils.RenameAllAsync() ` and uses Roslyn symbols to determine whether an identifier needs to
395+ be replaced.
396+
397+ The renamer has gone through several iterations, mainly due to performance reasons.
398+
399+ Previously, it used ` SymbolFinder.FindReferencesAsync() ` , which was replaced since it was far too slow for bigger APIs
400+ like the Microsoft bindings. ` FindReferencesAsync ` was not designed for mass replacement of all identifiers in a project
401+ and thus suffered an ` O(n^2) ` scaling (where ` n ` is the size of the project) since it scanned the entire project for
402+ each symbol replaced.
403+
404+ The current implementation, which is the ` LocationTransformationUtils ` class in the codebase, uses a
405+ ` CSharpSyntaxRewriter ` that visits every syntax node in the project and looks up symbols related to the node before
406+ deciding to replace it. This changes the scaling to ` O(n) ` with symbol lookup being the primary bottleneck. Symbol
407+ lookup is optimized by checking if the name of the identifier matches a name of the symbols to rename, which doubles the
408+ speed of renaming when it comes to the Vulkan bindings.
409+
410+ The reason the new renamer is part of the "location transformation" code is because the renamer has also been
411+ generalized to work with any transformation that needs to modify all references of a symbol. This notably was designed
412+ back when ` TransformHandles ` needed to simultaneously rename all references to a handle type and decrease the pointer
413+ dimension of the references to the type by one (eg: ` Buffer** ` becomes ` BufferHandle* ` ). This bulk modification ensures
414+ that symbol lookup only needs to occur once.
415+
416+ Side note: Arguably, "reference transformation" better describes this area of the codebase, but the name originally came
417+ from the ` ReferenceLocation ` type returned by ` SymbolFinder.FindReferencesAsync() ` .
0 commit comments