{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/41845","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/41845/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/41845/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/41845/events","html_url":"https://github.com/dotnet/corefx/pull/41845","id":508229406,"node_id":"MDExOlB1bGxSZXF1ZXN0MzI5MDYxODIz","number":41845,"title":"Use Sse2 instrinsics to make NeedsEscaping check faster for large JSON strings","user":{"login":"ahsonkhan","id":6527137,"node_id":"MDQ6VXNlcjY1MjcxMzc=","avatar_url":"https://avatars1.githubusercontent.com/u/6527137?v=4","gravatar_id":"","url":"https://api.github.com/users/ahsonkhan","html_url":"https://github.com/ahsonkhan","followers_url":"https://api.github.com/users/ahsonkhan/followers","following_url":"https://api.github.com/users/ahsonkhan/following{/other_user}","gists_url":"https://api.github.com/users/ahsonkhan/gists{/gist_id}","starred_url":"https://api.github.com/users/ahsonkhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahsonkhan/subscriptions","organizations_url":"https://api.github.com/users/ahsonkhan/orgs","repos_url":"https://api.github.com/users/ahsonkhan/repos","events_url":"https://api.github.com/users/ahsonkhan/events{/privacy}","received_events_url":"https://api.github.com/users/ahsonkhan/received_events","type":"User","site_admin":false},"labels":[{"id":1113158137,"node_id":"MDU6TGFiZWwxMTEzMTU4MTM3","url":"https://api.github.com/repos/dotnet/corefx/labels/area-System.Text.Json","name":"area-System.Text.Json","color":"d4c5f9","default":false},{"id":153500238,"node_id":"MDU6TGFiZWwxNTM1MDAyMzg=","url":"https://api.github.com/repos/dotnet/corefx/labels/tenet-performance","name":"tenet-performance","color":"c2e0c6","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/dotnet/corefx/milestones/44","html_url":"https://github.com/dotnet/corefx/milestone/44","labels_url":"https://api.github.com/repos/dotnet/corefx/milestones/44/labels","id":4497552,"node_id":"MDk6TWlsZXN0b25lNDQ5NzU1Mg==","number":44,"title":"5.0","description":".NET Core 5.0, next major release after 3.x. See [official release dates](https://github.com/dotnet/core/blob/master/roadmap.md) for details.\r\n\r\nWe will move important issues from Future to 5.0 as the priorities and dates for next release become more clear.","creator":{"login":"karelz","id":5776068,"node_id":"MDQ6VXNlcjU3NzYwNjg=","avatar_url":"https://avatars2.githubusercontent.com/u/5776068?v=4","gravatar_id":"","url":"https://api.github.com/users/karelz","html_url":"https://github.com/karelz","followers_url":"https://api.github.com/users/karelz/followers","following_url":"https://api.github.com/users/karelz/following{/other_user}","gists_url":"https://api.github.com/users/karelz/gists{/gist_id}","starred_url":"https://api.github.com/users/karelz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karelz/subscriptions","organizations_url":"https://api.github.com/users/karelz/orgs","repos_url":"https://api.github.com/users/karelz/repos","events_url":"https://api.github.com/users/karelz/events{/privacy}","received_events_url":"https://api.github.com/users/karelz/received_events","type":"User","site_admin":false},"open_issues":1089,"closed_issues":959,"state":"open","created_at":"2019-07-16T23:15:36Z","updated_at":"2019-10-17T22:51:40Z","due_on":"2020-11-30T08:00:00Z","closed_at":null},"comments":1,"created_at":"2019-10-17T04:39:14Z","updated_at":"2019-10-17T22:57:15Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/41845","html_url":"https://github.com/dotnet/corefx/pull/41845","diff_url":"https://github.com/dotnet/corefx/pull/41845.diff","patch_url":"https://github.com/dotnet/corefx/pull/41845.patch"},"body":"Here's the whole analysis and experimentation of different alternatives with benchmark results: https://gist.github.com/ahsonkhan/c566f5e7d65c1fde5a83a67be290c4ee\r\n\r\nIgnore the uap target changes (they were borrowed from https://github.com/dotnet/corefx/pull/41759) since it was happening anyway and I am not yet sure if its worth the effort to create different constants for uap (since intrinsics aren't built for that configuration).\r\n\r\nHere's the conclusion and next steps.\r\n\r\n## Conclusions:\r\nHere's a summary of the results when the user doesn't customize the encoder via the `JsonSerializerOptions` or `JsonWriterOptions` (i.e. uses the default encoder behavior).\r\n1) For end-to-end scenario (such as serializing commonly found objects/payloads), there is a 10-20% improvement.\r\n2) Writing relatively large JSON strings using the writer got ~30% faster (i.e. greater than 16 characters).\r\n3) Checking for escaping strings that are less than 8 characters is ~20-50% slower, but larger strings (i.e. greater than 16 character) got 2-3x faster.\r\n4) If a character is found that needs escaping within the first 8 characters, there is a 20-90% regression. Otherwise, there is a a 2-3x performance improvement depending on where the first character that needs escaping is found (say index greater than 16).\r\n\r\n## Next Steps:\r\n~1) Add similar support and tests for UTF-8 bytes, not just UTF-16 characters.~\r\n2) Evaluate if the trade-off is worth it for property names which tend to be small (2-8 characters), compared to values.\r\n3) Consider optimizing the commonly used built-in `JavascriptEncoder` statics using similar techniques.\r\n4) Apply non-Sse2 based optimizations where Sse2 isn't supported rather than processing one character at a time.\r\n5) Rather than returning the first index to escape, return the whole mask and escape all characters that need to be escaped at once (within the block of 8) and return back to the \"fast\" non-escaping path, rather than writing one character at a time whenever a single character is found that needs escaping.\r\n\r\ncc @steveharter, @tannergooding, @GrabYourPitchforks "},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/543397009","html_url":"https://github.com/dotnet/corefx/pull/41845#issuecomment-543397009","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/41845","id":543397009,"node_id":"MDEyOklzc3VlQ29tbWVudDU0MzM5NzAwOQ==","user":{"login":"ahsonkhan","id":6527137,"node_id":"MDQ6VXNlcjY1MjcxMzc=","avatar_url":"https://avatars1.githubusercontent.com/u/6527137?v=4","gravatar_id":"","url":"https://api.github.com/users/ahsonkhan","html_url":"https://github.com/ahsonkhan","followers_url":"https://api.github.com/users/ahsonkhan/followers","following_url":"https://api.github.com/users/ahsonkhan/following{/other_user}","gists_url":"https://api.github.com/users/ahsonkhan/gists{/gist_id}","starred_url":"https://api.github.com/users/ahsonkhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahsonkhan/subscriptions","organizations_url":"https://api.github.com/users/ahsonkhan/orgs","repos_url":"https://api.github.com/users/ahsonkhan/repos","events_url":"https://api.github.com/users/ahsonkhan/events{/privacy}","received_events_url":"https://api.github.com/users/ahsonkhan/received_events","type":"User","site_admin":false},"created_at":"2019-10-17T22:57:15Z","updated_at":"2019-10-17T22:57:15Z","author_association":"MEMBER","body":"Any other feedback?"}}
{"actor":{"display_login":"ahsonkhan"}}