{"action":"created","issue":{"url":"https://api.github.com/repos/dlang/phobos/issues/5017","repository_url":"https://api.github.com/repos/dlang/phobos","labels_url":"https://api.github.com/repos/dlang/phobos/issues/5017/labels{/name}","comments_url":"https://api.github.com/repos/dlang/phobos/issues/5017/comments","events_url":"https://api.github.com/repos/dlang/phobos/issues/5017/events","html_url":"https://github.com/dlang/phobos/pull/5017","id":198984385,"node_id":"MDExOlB1bGxSZXF1ZXN0MTAwMzEwNjEz","number":5017,"title":"Slight optimization for std.conv.text/wtext/dtext","user":{"login":"JackStouffer","id":680068,"node_id":"MDQ6VXNlcjY4MDA2OA==","avatar_url":"https://avatars0.githubusercontent.com/u/680068?v=4","gravatar_id":"","url":"https://api.github.com/users/JackStouffer","html_url":"https://github.com/JackStouffer","followers_url":"https://api.github.com/users/JackStouffer/followers","following_url":"https://api.github.com/users/JackStouffer/following{/other_user}","gists_url":"https://api.github.com/users/JackStouffer/gists{/gist_id}","starred_url":"https://api.github.com/users/JackStouffer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JackStouffer/subscriptions","organizations_url":"https://api.github.com/users/JackStouffer/orgs","repos_url":"https://api.github.com/users/JackStouffer/repos","events_url":"https://api.github.com/users/JackStouffer/events{/privacy}","received_events_url":"https://api.github.com/users/JackStouffer/received_events","type":"User","site_admin":false},"labels":[{"id":402394778,"node_id":"MDU6TGFiZWw0MDIzOTQ3Nzg=","url":"https://api.github.com/repos/dlang/phobos/labels/Trivial","name":"Trivial","color":"0e8a16","default":false},{"id":416187218,"node_id":"MDU6TGFiZWw0MTYxODcyMTg=","url":"https://api.github.com/repos/dlang/phobos/labels/optimization","name":"optimization","color":"1d76db","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-01-05T15:37:45Z","updated_at":"2018-06-11T19:52:19Z","closed_at":"2017-01-13T10:50:57Z","author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/dlang/phobos/pulls/5017","html_url":"https://github.com/dlang/phobos/pull/5017","diff_url":"https://github.com/dlang/phobos/pull/5017.diff","patch_url":"https://github.com/dlang/phobos/pull/5017.patch"},"body":"Increase the performance of `textImpl` by\r\n\r\n* Reducing GC allocations with numbers by using `toChars` rather than `to`, which allocates a temporary array and then throws it away\r\n* Using a very dumb heuristic to pre-allocate space for the elements \r\n\r\nJust adding the `toChars` case gave a small boost in LDC and no difference in DMD. But, the heuristic added a lot of performance.\r\n\r\nRecording performance gains of 12.8% with LDC and 5.5% with DMD\r\n\r\n```\r\n$ ldc2 -O5 -release test.d && ./test\r\nresult\t1 sec, 435 ms, 49 μs, and 4 hnsecs\r\nresult2\t1 sec, 251 ms, 957 μs, and 6 hnsecs\r\n\r\n$ dmd -O -inline -release -noboundscheck test.d &&./test\r\nresult\t2 secs, 510 ms, 745 μs, and 2 hnsecs\r\nresult2\t2 secs, 372 ms, 147 μs, and 4 hnsecs\r\n```\r\n\r\nThe code\r\n\r\n```\r\nimport std.stdio;\r\nimport std.range;\r\nimport std.algorithm;\r\nimport std.traits;\r\nimport std.container;\r\nimport std.meta;\r\nimport std.conv;\r\nimport std.datetime;\r\n\r\nenum testCount = 1_000_000;\r\n\r\nprivate S textImpl(S, U...)(U args)\r\n{\r\n    static if (U.length == 0)\r\n    {\r\n        return null;\r\n    }\r\n    else static if (U.length == 1)\r\n    {\r\n        return to!S(args[0]);\r\n    }\r\n    else\r\n    {\r\n        import std.array : appender;\r\n\r\n        auto app = appender!S();\r\n\r\n        foreach (arg; args)\r\n            app.put(arg.to!S);\r\n\r\n        return app.data;\r\n    }\r\n}\r\n\r\n\r\nprivate S textImpl2(S, U...)(U args)\r\n{\r\n    static if (U.length == 0)\r\n    {\r\n        return null;\r\n    }\r\n    else static if (U.length == 1)\r\n    {\r\n        return to!S(args[0]);\r\n    }\r\n    else\r\n    {\r\n        import std.array : appender;\r\n\r\n        auto app = appender!S();\r\n\r\n        // assume that on average, parameters will have less\r\n        // than 20 elements\r\n        app.reserve(U.length * 20);\r\n\r\n        foreach (arg; args)\r\n        {\r\n            static if (is(Unqual!T == uint) || is(Unqual!T == ulong) || is(Unqual!T == int) || is(Unqual!T == long))\r\n                app.put(arg.toChars);\r\n            else\r\n                app.put(arg.to!S);\r\n        }\r\n\r\n        return app.data;\r\n    }\r\n}\r\n\r\n\r\nvoid main()\r\n{\r\n    auto result = to!Duration(benchmark!(() => textImpl!dstring(4243, ' ', 1.54321, \": xyz\", 333, \"Another test\"))(testCount)[0]);\r\n    auto result2 = to!Duration(benchmark!(() => textImpl2!dstring(4243, ' ', 1.54321, \": xyz\", 333, \"Another test\"))(testCount)[0]);\r\n\r\n    writeln(\"result\", \"\\t\", result);\r\n    writeln(\"result2\", \"\\t\", result2);\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/dlang/phobos/issues/comments/396365385","html_url":"https://github.com/dlang/phobos/pull/5017#issuecomment-396365385","issue_url":"https://api.github.com/repos/dlang/phobos/issues/5017","id":396365385,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NjM2NTM4NQ==","user":{"login":"BBasile","id":16154339,"node_id":"MDQ6VXNlcjE2MTU0MzM5","avatar_url":"https://avatars1.githubusercontent.com/u/16154339?v=4","gravatar_id":"","url":"https://api.github.com/users/BBasile","html_url":"https://github.com/BBasile","followers_url":"https://api.github.com/users/BBasile/followers","following_url":"https://api.github.com/users/BBasile/following{/other_user}","gists_url":"https://api.github.com/users/BBasile/gists{/gist_id}","starred_url":"https://api.github.com/users/BBasile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BBasile/subscriptions","organizations_url":"https://api.github.com/users/BBasile/orgs","repos_url":"https://api.github.com/users/BBasile/repos","events_url":"https://api.github.com/users/BBasile/events{/privacy}","received_events_url":"https://api.github.com/users/BBasile/received_events","type":"User","site_admin":false},"created_at":"2018-06-11T19:52:19Z","updated_at":"2018-06-11T19:52:19Z","author_association":"CONTRIBUTOR","body":"That maybe more simply because toChars is not called anymore."}}
{"actor":{"display_login":"BBasile"}}