Minor tweaks to avoid some allocations#514
Conversation
Fix up some places where: - Char literals were used in string concatenation, resulting in boxing and string allocations that could be avoided if a string literal were used instead - Value types were used in string concatenation, resulting in unnecessary boxing allocations
|
I'm really on the fence about this. While i totally understand the concern about allocations, it's really really unpleasant to have to put in this sort of microoptimization, instead of just writing clear code that the system appropriately optimizes. Note: as for #415, i think it should be merged in, with just a small tweak. Specifically, it should only apply to the core set of special value types that C# knows are pure. i.e. bools, char, and all the numerics. This would get you the majority of savings, without having to worry about changing semantics, while still allowing code to be written cleanly. |
|
Some of these, e.g. the string literal instead of a char literal, are IMHO exactly as readable (and you'd want to do those even with what's in #415; I noted in that pull request it'd be nice if the compiler was allowed to do that substitution as well). Others that just add .ToString () don't seem particularly difficult or less clean. I agree in other cases it's less legible. |
|
👍 |
|
👍 |
|
+1 unless we can relax performance RI gate or relax our performance goal somehow (100% typing responsiveness under 65ms) , unfortunately we need to care about these kinds of stuff in managed code. many people has been pushing somehow relaxing performance RI gate (especially when regression is 50ms or something below like that). Not sure how type script is doing RPS test but until process changes, not much we can do. |
Minor tweaks to avoid some allocations
Just some small tweaks to fix up some places where:
Most of these are under the assumption that #415 will not be merged.