{"id":15410890,"url":"https://github.com/nilproject/nil.exev","last_synced_at":"2025-08-10T00:15:16.214Z","repository":{"id":154637036,"uuid":"632390373","full_name":"nilproject/NiL.Exev","owner":"nilproject","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-18T11:35:26.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-01T01:08:42.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nilproject.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-25T10:02:43.000Z","updated_at":"2023-04-25T10:02:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"18cd573b-8f99-40ea-b2cc-ae9100958996","html_url":"https://github.com/nilproject/NiL.Exev","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/nilproject/NiL.Exev","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilproject%2FNiL.Exev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilproject%2FNiL.Exev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilproject%2FNiL.Exev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilproject%2FNiL.Exev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nilproject","download_url":"https://codeload.github.com/nilproject/NiL.Exev/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilproject%2FNiL.Exev/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269656018,"owners_count":24454571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T16:46:49.445Z","updated_at":"2025-08-10T00:15:16.141Z","avatar_url":"https://github.com/nilproject.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"NiL.Exev\u003cbr\u003e\r\n==\r\nCustom evaluator and serializer for System.Linq.Expression. \r\n\r\n\u003cbr\u003e\r\nWhat's the point?\r\n\u003cdetails\u003e\r\n\u003csummary\u003eit's up to 100 times faster then compile-and-run.\u003c/summary\u003e\r\n\r\n```c#\r\nExpression\u003cFunc\u003cstring, string, string\u003e\u003e expression = (a, b) =\u003e a + b;\r\nvar repeats = 100_000;\r\n\r\nvar sw = Stopwatch.StartNew();\r\nfor (var i = 0; i \u003c repeats; i++)\r\n{\r\n    var result = expression.Compile()(\"hello, \", \"world\");\r\n    Debug.Assert(result is \"hello, world\");\r\n}\r\nConsole.WriteLine(sw.Elapsed); // 00:00:03.8659292\r\n\r\nvar evaluator = new ExpressionEvaluator();\r\n\r\nsw.Restart();\r\nfor (var i = 0; i \u003c repeats; i++)\r\n{\r\n    var result = evaluator.Eval(\r\n        expression.Body,\r\n        new[]\r\n        {\r\n            new Parameter(expression.Parameters[0], \"hello, \"),\r\n            new Parameter(expression.Parameters[1], \"world\")\r\n        });\r\n    Debug.Assert(result is \"hello, world\");\r\n}\r\nConsole.WriteLine(sw.Elapsed); // 00:00:00.0391234\r\n```\r\n\r\n\u003c/details\u003e\r\n\r\n\u003cdetails\u003e\r\n\u003csummary\u003eAnd only 10 times slower when both are prepared (but you can do not use it in this case, of course)\u003c/summary\u003e\r\n\r\n```c#\r\nExpression\u003cFunc\u003cstring, string, string\u003e\u003e expression = (a, b) =\u003e a + b;\r\nvar repeats = 10_000_000;\r\n\r\nvar compile = expression.Compile();\r\nvar sw = Stopwatch.StartNew();\r\nfor (var i = 0; i \u003c repeats; i++)\r\n{\r\n    var result = compile(\"hello, \", \"world\");\r\n    Debug.Assert(result is \"hello, world\");\r\n}\r\nsw.Stop();\r\nConsole.WriteLine(sw.Elapsed); // 00:00:00.1274875\r\n\r\nvar evaluator = new ExpressionEvaluator();\r\n\r\nvar args = new[]\r\n{\r\n    new Parameter(expression.Parameters[0], \"\"),\r\n    new Parameter(expression.Parameters[1], \"\")\r\n};\r\nsw.Restart();\r\nfor (var i = 0; i \u003c repeats; i++)\r\n{\r\n    args[0].Value = \"hello, \";\r\n    args[1].Value = \"world\";\r\n    var result = evaluator.Eval(expression.Body, args);\r\n    Debug.Assert(result is \"hello, world\");\r\n}\r\nsw.Stop();\r\nConsole.WriteLine(sw.Elapsed); // 00:00:01.1773341\r\n```\r\n\r\n\u003c/details\u003e\r\n\u003cbr\u003e\r\nAnd what? When it can be helpful?\r\n\u003cdetails\u003e\r\n\u003csummary\u003eWhen you are making you own super-duper-mega RPC protocol\u003c/summary\u003e\r\n\r\n```C#\r\n// Сharacters\r\nvar myDb = new Dictionary\u003cstring, string\u003e { [\"someKey\"] = \"someValue\" }; // some class to access to data on a server\r\nvar serializer = new ExpressionSerializer();\r\nvar deserializer = new ExpressionDeserializer();\r\nvar evaluator = new ExpressionEvaluator();\r\nvar networkStream = new MemoryStream(); // just imagine that this is network stream\r\n\r\n// Client\r\nExpression\u003cFunc\u003cDictionary\u003cstring, string\u003e, string\u003e\u003e expression = serverDictionary =\u003e serverDictionary[\"someKey\"];\r\nvar serialized = serializer.Serialize(expression);\r\n            \r\nnetworkStream.Write(serialized);        // transfer to a server\r\nnetworkStream.Seek(0, SeekOrigin.Begin);\r\n\r\n// Server            \r\nvar receivedRequest = new byte[networkStream.Length];\r\nnetworkStream.Read(receivedRequest, 0, receivedRequest.Length);\r\n\r\nvar deserialized = deserializer.Deserialize(receivedRequest);            \r\n\r\nvar result = (evaluator.Eval(deserialized) as Func\u003cDictionary\u003cstring, string\u003e, string\u003e)!(myDb);\r\n\r\nvar serializedResult = serializer.Serialize(Expression.Constant(result));\r\n\r\nnetworkStream.SetLength(0);             // transfer to a client\r\nnetworkStream.Write(serializedResult);\r\nnetworkStream.Seek(0, SeekOrigin.Begin);\r\n\r\n// Client\r\nvar receivedResponse = new byte[networkStream.Length];\r\nnetworkStream.Read(receivedResponse, 0, receivedResponse.Length);\r\nvar response = deserializer.Deserialize(receivedResponse) as ConstantExpression;\r\n\r\nDebug.Assert(response!.Value is \"someValue\");\r\n```\r\n\r\n\u003c/details\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilproject%2Fnil.exev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnilproject%2Fnil.exev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilproject%2Fnil.exev/lists"}