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 DD735200C08 for ; Thu, 26 Jan 2017 16:06:31 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id DC0D8160B33; Thu, 26 Jan 2017 15:06:31 +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 2FAD4160B40 for ; Thu, 26 Jan 2017 16:06:31 +0100 (CET) Received: (qmail 66647 invoked by uid 500); 26 Jan 2017 15:06:30 -0000 Mailing-List: contact issues-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@hbase.apache.org Received: (qmail 66636 invoked by uid 99); 26 Jan 2017 15:06:30 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Jan 2017 15:06:30 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id B91401A082E for ; Thu, 26 Jan 2017 15:06:29 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.199 X-Spam-Level: X-Spam-Status: No, score=-1.199 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 526MqyYNNPwq for ; Thu, 26 Jan 2017 15:06:28 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id E39925F1F4 for ; Thu, 26 Jan 2017 15:06:27 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 11C79E040C for ; Thu, 26 Jan 2017 15:06:25 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 737862528E for ; Thu, 26 Jan 2017 15:06:24 +0000 (UTC) Date: Thu, 26 Jan 2017 15:06:24 +0000 (UTC) From: "Jean-Marc Spaggiari (JIRA)" To: issues@hbase.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (HBASE-17512) Optimize ServerName.parsePort() to reduce objects creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 26 Jan 2017 15:06:32 -0000 [ https://issues.apache.org/jira/browse/HBASE-17512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15839822#comment-15839822 ] Jean-Marc Spaggiari commented on HBASE-17512: --------------------------------------------- Thanks for doing it [~stack]. Good to know. Where can I find this list? > Optimize ServerName.parsePort() to reduce objects creation > ---------------------------------------------------------- > > Key: HBASE-17512 > URL: https://issues.apache.org/jira/browse/HBASE-17512 > Project: HBase > Issue Type: Bug > Affects Versions: 1.2.4 > Reporter: Jean-Marc Spaggiari > Assignee: Samuel David Glover > Priority: Minor > Labels: beginner > > ServerName.parsePort() calls the split method on a string. This string format is like "www.example.org,1234,1212121212" where we try to get only 1234. Each time the split() method is called, it creates 4 objets. 3 strings and an array. And we just us one of those strings. > This this method is called in a single place. In the constructor: > {code} > private ServerName(final String serverName) { > this(parseHostname(serverName), parsePort(serverName), > parseStartcode(serverName)); > } > {code} > So parsePort creates 3 string. Te hostname, the port, the startcode, but returns only the port, while we call 2 other methods to redo the exact same work. > This constructor is called only there: > {code} > /** > * Retrieve an instance of ServerName. > * Callers should use the equals method to compare returned instances, though we may return > * a shared immutable object as an internal optimization. > */ > public static ServerName valueOf(final String serverName) { > return new ServerName(serverName); > } > {code} > and this is called here and there. Not intensively, but still, should be cleaned. > Instead of using split, something like this might do better: > {code} > public static int parsePort(final String serverName) { > int indexStart = serverName.indexOf(SERVERNAME_SEPARATOR); > int indexStop = serverName.lastIndexOf(SERVERNAME_SEPARATOR); > return Integer.parseInt(serverName.substring(indexStart + 1, indexStop)); > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)