Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 540CA200B4F for ; Tue, 26 Jul 2016 19:29:19 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 52AC3160A75; Tue, 26 Jul 2016 17:29:19 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 98146160A69 for ; Tue, 26 Jul 2016 19:29:18 +0200 (CEST) Received: (qmail 75504 invoked by uid 500); 26 Jul 2016 17:29:17 -0000 Mailing-List: contact dev-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list dev@flex.apache.org Received: (qmail 75492 invoked by uid 99); 26 Jul 2016 17:29:17 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jul 2016 17:29:17 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id D26E4C0C03 for ; Tue, 26 Jul 2016 17:29:16 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.179 X-Spam-Level: * X-Spam-Status: No, score=1.179 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id VyVN-zlRKL7P for ; Tue, 26 Jul 2016 17:29:14 +0000 (UTC) Received: from mail-qk0-f169.google.com (mail-qk0-f169.google.com [209.85.220.169]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with ESMTPS id CEEE35FE22 for ; Tue, 26 Jul 2016 17:29:13 +0000 (UTC) Received: by mail-qk0-f169.google.com with SMTP id x1so12342953qkb.3 for ; Tue, 26 Jul 2016 10:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=nw1wSHJL7Pl6XjAM4C2XANcUZ1tCr4zbGRRz00nCboM=; b=GiJI42JIH5YveDeepyiMvelyAyCyrFq/bTl0OsLe4ebOdBVgWVGi6ojZ9sj0VZEOi+ 2t3X82PVCAGRqfv2vtkbIAVSSuQYQEjwvd1fLoV0otf8N3TbcXgDSv2e06SQY3EzV4kW i5voPyREXSSWV6ABOEIKvsuaTIq46zFPrHqfLLQtdxtG8dKtJyZ15Djer7WSIngpGe7I 6KCADuEgqDJ6vvvQuFDqpLzvKwx4LJcCM8gSUHsawfK8pEVLgIhiB/IELMzDlqG77D/N 7FjEO3fjagqk/WgIcgIdpxWWaGw46zKpOFR/EkE82KGVAPJSPHsQSW79uPNl4s5Zev9h cchQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=nw1wSHJL7Pl6XjAM4C2XANcUZ1tCr4zbGRRz00nCboM=; b=V2uGDaTth/nXpULOCh+Y7IJOCpY/deMYHBNaa5mcNmLOwcqteLx3HoOoy1q72Njg3C ikoWtlohY+XpTafoMEAiguLE3uTylwkxsuZqA4doPj2uZBaRK3vncICxKd2UuVm86sx5 9pVdtLwEW/4Ykw5lX/s1FMMbM5CSmNb/2pQcH4+WYt9lF8/+dzoHYhd6M6Lifod1ZA0i 5kBytJURkMilffpeRfUZrMxDoSEGqhX1uZHMb0YACH4wS7F/TG4Y4XuOExAM9mMUY54E 9Anr0Y5pIDUT2Z7rzx16B13w/FV+tDV0wXt1a0SXrzWOcRZKFjn9ufGvvsocZBAh+Z8q dsvw== X-Gm-Message-State: AEkoouv25+QBRZo71wQZxwnqnScYWuETeOYf2PSXG8CMOaerB/t+fz8uQVkRmGFsDlfNCrUWDFDbwUDhqLxZXg== X-Received: by 10.55.177.197 with SMTP id a188mr29456289qkf.167.1469554152778; Tue, 26 Jul 2016 10:29:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.39.6 with HTTP; Tue, 26 Jul 2016 10:28:33 -0700 (PDT) In-Reply-To: References: From: Josh Tynjala Date: Tue, 26 Jul 2016 10:28:33 -0700 Message-ID: Subject: Re: [FlexJS] Javascript efficient code patterns To: dev@flex.apache.org Content-Type: multipart/alternative; boundary=94eb2c070d2041328905388d3d3e archived-at: Tue, 26 Jul 2016 17:29:19 -0000 --94eb2c070d2041328905388d3d3e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Yeah, push() is terribly bad for performance because of the GC overhead from the ...rest Array. In Starling and Feathers, we always try to avoid push() whenever possible. We usually use bracket syntax instead: array[array.length] =3D newValue; In loops, it's possible to use a local integer counter instead of checking the length property every time. counter =3D 0; //or counter =3D array.length, if it isn't empty for(...) { array[counter] =3D newValue; counter++; } - Josh On Tue, Jul 26, 2016 at 10:15 AM, Alex Harui wrote: > > > On 7/26/16, 1:40 AM, "Harbs" wrote: > > >I noticed a couple of things: > >1. There=E2=80=99s lots of String(val) casts in FlexJS code. This practi= ce is > >considered =E2=80=9Cbad=E2=80=9D practice in Javascript where implicit c= onversion is > >generally quicker. So in a case where a number can be converted > >implicitly, the cast should be completely skipped and even when a number > >needs to be converted to a string, =E2=80=9C=E2=80=9D + val is more effi= cient than > >String(val). This is especially true in FlexJS where (I believe) such > >code will result in org.apache.flex.Language.as(val,=E2=80=9DString=E2= =80=9D). > > I'm not seeing this. What source code is generating String(val) calls? > Regarding optimization, do we know if GCC will do this ("" + val) > optimization for us? > > In general, there is a big TODO around type conversions. > > > > >2. String concatenation: I=E2=80=99m not sure how much of an issue this = is in > >current browsers, but using aray.join() to build a string was MUCH faste= r > >than building strings using the plus operator. For longer strings the > >difference was dramatic. > > If I understood this, it would be hard for the compiler to generate the > right code for all browsers. You could create a StringBuilder class that > checks platforms and runs different code at runtime. > > FWIW, Flex UIDUtils uses ByteArray because, IIRC, while array.join() migh= t > be fast, the array.push() is horribly slow and generates a lot of GC > activity. > > HTH, > -Alex > > --94eb2c070d2041328905388d3d3e--