{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/13924","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/13924/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/13924/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/13924/events","html_url":"https://github.com/dotnet/corefx/issues/13924","id":191360529,"number":13924,"title":"Expose a cached StringBuilder","user":{"login":"JeremyKuhne","id":8184940,"avatar_url":"https://avatars.githubusercontent.com/u/8184940?v=3","gravatar_id":"","url":"https://api.github.com/users/JeremyKuhne","html_url":"https://github.com/JeremyKuhne","followers_url":"https://api.github.com/users/JeremyKuhne/followers","following_url":"https://api.github.com/users/JeremyKuhne/following{/other_user}","gists_url":"https://api.github.com/users/JeremyKuhne/gists{/gist_id}","starred_url":"https://api.github.com/users/JeremyKuhne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JeremyKuhne/subscriptions","organizations_url":"https://api.github.com/users/JeremyKuhne/orgs","repos_url":"https://api.github.com/users/JeremyKuhne/repos","events_url":"https://api.github.com/users/JeremyKuhne/events{/privacy}","received_events_url":"https://api.github.com/users/JeremyKuhne/received_events","type":"User","site_admin":false},"labels":[{"id":153714228,"url":"https://api.github.com/repos/dotnet/corefx/labels/api-needs-work","name":"api-needs-work","color":"207de5","default":false},{"id":174276033,"url":"https://api.github.com/repos/dotnet/corefx/labels/area-System.Runtime","name":"area-System.Runtime","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-23T19:25:29Z","updated_at":"2016-11-23T19:51:06Z","closed_at":null,"body":"We use `StringBuilderCache` to improve performance for short-lived usages of `StringBuilder`. Numerous other codebases have copied this. I want to suggest that we: (1) expose `StringBuilderCache` and/or (2) expose a cached `StringBuilder` on `StringBuilder`.\r\n\r\n### New Member Option A\r\nAligns with `StringBuilderCache`, although I prefer to flip the ordering of the words for `GetStringAndRelease`- it makes more sense from a discovery perspective.\r\n\r\n``` diff\r\nnamespace System.Text\r\n{\r\n  public sealed class StringBuilder\r\n  {\r\n+    public static StringBuilder Acquire(int capacity);\r\n+    public static void Release(StringBuilder sb);\r\n+    public static string ReleaseAndGetString(StringBuilder sb);\r\n  }\r\n}\r\n```\r\n\r\n### New Member Option B\r\nAligns with `ArrayPool` terminology.\r\n\r\n``` diff\r\nnamespace System.Text\r\n{\r\n  public sealed class StringBuilder\r\n  {\r\n+    public static StringBuilder Rent(int capacity);\r\n+    public static void Return(StringBuilder sb);\r\n+    public static string ReturnAndGetString(StringBuilder sb);\r\n  }\r\n}\r\n```\r\n\r\n### Expose StringBuilderCache Option\r\n\r\n``` diff\r\nnamespace System.Text\r\n{\r\n+  public static class StringBuilderCache\r\n+  {\r\n+    public static StringBuilder Acquire(int capacity);\r\n+    public static void Release(StringBuilder sb);\r\n+    public static string ReleaseAndGetString(StringBuilder sb);\r\n+  }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/262614629","html_url":"https://github.com/dotnet/corefx/issues/13924#issuecomment-262614629","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/13924","id":262614629,"user":{"login":"jkotas","id":6668460,"avatar_url":"https://avatars.githubusercontent.com/u/6668460?v=3","gravatar_id":"","url":"https://api.github.com/users/jkotas","html_url":"https://github.com/jkotas","followers_url":"https://api.github.com/users/jkotas/followers","following_url":"https://api.github.com/users/jkotas/following{/other_user}","gists_url":"https://api.github.com/users/jkotas/gists{/gist_id}","starred_url":"https://api.github.com/users/jkotas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkotas/subscriptions","organizations_url":"https://api.github.com/users/jkotas/orgs","repos_url":"https://api.github.com/users/jkotas/repos","events_url":"https://api.github.com/users/jkotas/events{/privacy}","received_events_url":"https://api.github.com/users/jkotas/received_events","type":"User","site_admin":false},"created_at":"2016-11-23T19:51:06Z","updated_at":"2016-11-23T19:51:06Z","body":"I do not think we should expose this. The StringBuilderCache has bad properties: it only works for small strings, it is one per thread and stays allocated forever.\r\n\r\nWe should be snapping to ArrayPool for any kind of similar pooling. Discussed in https://github.com/dotnet/corefx/pull/13875#issuecomment-262293493.\r\n\r\nIf we need to make the string formatting cheaper, we should create an small internal helper type like the one I have described in #13875 that works on top of ArrayPool.\r\n\r\nEventually, the public API for this should be addressed by low-allocation formatters being developer in corefxlab."}}
{"actor":{"display_login":"jkotas"}}