From issues-return-41667-archive-asf-public=cust-asf.ponee.io@openwhisk.apache.org Fri Nov 29 09:06:30 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 45242180657 for ; Fri, 29 Nov 2019 10:06:30 +0100 (CET) Received: (qmail 77185 invoked by uid 500); 29 Nov 2019 09:06:29 -0000 Mailing-List: contact issues-help@openwhisk.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwhisk.apache.org Delivered-To: mailing list issues@openwhisk.apache.org Received: (qmail 77163 invoked by uid 99); 29 Nov 2019 09:06:29 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Nov 2019 09:06:29 +0000 From: GitBox To: issues@openwhisk.apache.org Subject: [GitHub] [openwhisk-runtime-dotnet] kamyker commented on issue #26: Raw requests to skip JObject conversion Message-ID: <157501838957.16366.7447833545954244785.gitbox@gitbox.apache.org> Date: Fri, 29 Nov 2019 09:06:29 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit kamyker commented on issue #26: Raw requests to skip JObject conversion URL: https://github.com/apache/openwhisk-runtime-dotnet/issues/26#issuecomment-559715123 Thought that these ``` string body = await new StreamReader(httpContext.Request.Body).ReadToEndAsync(); JObject inputObject = string.IsNullOrEmpty(body) ? null : JObject.Parse(body); ``` should be replaced with ``` JObject inputObject = await JObject.LoadAsync(new JsonTextReader(new StreamReader(httpContext.Request.Body))); ``` but after testing it seems that JObject.LoadAsync is 2-3 times slower. JObject.Load is few % faster but no async at all so worse solution. Did few more tests and deserializing into defined object is faster than JObject so @shawnallen85 idea will be faster than current one. Below is 4 times faster: ``` //Type functionInputType somewhere defined using ( StreamReader sr = new StreamReader( stream ) ) using ( JsonReader r = new JsonTextReader( sr ) ) { while ( r.Read() ) { if ( r.Value != null && r.Depth == 1 ) { if ( r.TokenType == JsonToken.PropertyName ) { currentProperty = r.Value.ToString(); if ( currentProperty == "value" ) { r.Read(); body = typeof( JsonSerializer ).GetMethods().FirstOrDefault( FindDeserializerMethod ) ?.MakeGenericMethod( functionInputType ).Invoke( new JsonSerializer(), new object[] { r } ); bool FindDeserializerMethod( MethodInfo m ) { var parameters = m.GetParameters(); return m.Name.Equals( "Deserialize", StringComparison.OrdinalIgnoreCase ) && m.IsGenericMethod && parameters.Length == 1 && parameters[0].ParameterType == typeof( JsonReader ); } } else { r.Read(); if ( r.TokenType == JsonToken.String ) //other types here also? numbers? { string envKey = $"__OW_{currentProperty.ToUpperInvariant()}"; StringBuilder sb = new StringBuilder(); string envVal = r.Value != null ? r.Value.ToString() : ""; Environment.SetEnvironmentVariable( envKey, envVal ); Console.WriteLine( $"SetEnvironmentVariable: {envKey}, {envVal}" ); } else { r.Skip(); } } } } } } ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services