From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 6C8FD17CDC65 for ; Thu, 7 Feb 2013 00:42:26 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 2CB15EA6F2F for ; Thu, 7 Feb 2013 00:25:43 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id EDBFF97A827 for ; Thu, 7 Feb 2013 00:25:42 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=gmail.com Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Pjh7ZNq7Blbx for ; Thu, 7 Feb 2013 00:25:42 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id CB19B97A826 for ; Thu, 7 Feb 2013 00:25:42 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id BF81A95241B for ; Thu, 7 Feb 2013 00:25:39 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id 0F5323C2294DD; Thu, 7 Feb 2013 00:25:38 +0900 (JST) Received: from mail-we0-f175.google.com (mail-we0-f175.google.com [74.125.82.175]) by carbon.ruby-lang.org (Postfix) with ESMTP id C690A3C21F74E for ; Thu, 7 Feb 2013 00:25:36 +0900 (JST) Received: by mail-we0-f175.google.com with SMTP id x8so1249490wey.34 for ; Wed, 06 Feb 2013 07:25:34 -0800 (PST) Received: from [192.168.1.4] (ip86-128-172-82.adsl2.static.versatel.nl. [82.172.128.86]) by mx.google.com with ESMTPS id fx5sm3859275wib.11.2013.02.06.07.18.08 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 06 Feb 2013 07:18:09 -0800 (PST) Delivered-To: ruby-core@ruby-lang.org Date: Thu, 7 Feb 2013 00:25:37 +0900 Posted: Wed, 06 Feb 2013 16:18:07 +0100 From: Yorick Peterse Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:51926] Re: [ruby-trunk - Feature #7792] Make symbols and strings the same thing To: ruby-core@ruby-lang.org Message-Id: <5112742F.5000403@gmail.com> In-Reply-To: <51126D47.3090902@gmail.com> References: <51126A63.4090302@gmail.com> <51126D47.3090902@gmail.com> X-ML-Name: ruby-core X-Mail-Count: 51926 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 X-Greylist: delayed 444 seconds by postgrey-1.27 at carbon; Thu, 07 Feb 2013 00:25:36 JST DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=af0Xmu4jqHcE2+0xfjxTrOMC+gPv5ElmmISKo2gEKlo=; b=SuIrhf/b64EQmLWzXGovtz7Gyi4EV04XKLAEqO5QorOxNGe10Mz+St1IYSFho3dW3f fpTeyv8TuAiYjcio4qm+O2CGqQ6VHQzj4dydytasaQVFo/EN5DutbZnU/mPnQMUF4ahz AKpKJ3gbhhfHTUH4hcBL0nPExvddxWkYLw8jUIIyoOQz7euAx2ujGE3UhhoP1huhKqjz Mw49nXQcp1vvwFOdeTIyoxia/SRDjG7le50FS7haGZNE3F/Y3IE9QTzjQ0ATGa+VXhiS ZXzPUbRddqL27u56bX2efzDDl1Umr0DsZ2vgXADRR/WtTdn7edP48hecWaUApe2GRD7z eCaA== X-Received: by 10.180.86.36 with SMTP id m4mr5656580wiz.5.1360163890916; Wed, 06 Feb 2013 07:18:10 -0800 (PST) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: I don't think I'm following you, can you explain what's supposedly ironic about it? Using Hashie only "slows" things down based on whether you use Symbols, Strings or object attributes. Unless you use it *all* over the place the performance impact is small. I personally don't fully agree with what Hashie does because I believe people should be competent enough to realize that when they take in external data it's going to be String instances (for keys that is). Having said that, I think fundamentally changing the way Ruby works when it comes to handling Strings and Symbols because developers can't be bothered fixing the root cause of the problem is flawed. If you're worried about a ddos stop converting everything to Symbols. If you're worried about not remember what key type to use, use a custom object or document it so that people can easily know. While Ruby is all about making the lifes easier I really don't want it to become a language that spoon feeds programmers because they're too lazy to type 1 extra character *or* convert the output manually. Or better: use a custom object as mention above. The benchmark you posted is flawed because it does much, much more than benchmarking the time required to create a new Symbol or String instance. Lets take a look at the most basic benchmark of these two data types: require 'benchmark' amount = 50000000 Benchmark.bmbm(40) do |run| run.report 'Symbols' do amount.times do :foobar end end run.report 'Strings' do amount.times do 'foobar' end end end On the laptop I'm currently using this results in the following output: Rehearsal ---------------------------------------------------------------------------- Symbols 2.310000 0.000000 2.310000 ( 2.311325) Strings 5.710000 0.000000 5.710000 ( 5.725365) ------------------------------------------------------------------- total: 8.020000sec user system total real Symbols 2.670000 0.000000 2.670000 ( 2.680489) Strings 6.560000 0.010000 6.570000 ( 6.584651) This shows that the use of Strings is roughly 2,5 times slower than Symbols. Now execution time isn't the biggest concern in this case, it's memory usage. For this I used the following basic benchmark: def get_memory return `ps -o rss= #{Process.pid}`.strip.to_f end def benchmark_memory before = get_memory yield return get_memory - before end amount = 50000000 puts "Start memory: #{get_memory} KB" symbols = benchmark_memory do amount.times do :foobar end end strings = benchmark_memory do amount.times do 'foobar' end end puts "Symbols used #{symbols} KB" puts "Strings used #{strings} KB" This results in the following: Start memory: 4876.0 KB Symbols used 0.0 KB Strings used 112.0 KB Now I wouldn't be too surprised if there's some optimization going on because I'm re-creating the same values over and over again but it already shows a big difference between the two. To cut a long story short: I can understand what you're trying to get at, both with the two data types being merged and the ddos issue. However, I feel neither of these issues are an issue directly related to Ruby itself. If Ruby were to automatically convert things to Symbols for you then yes, but in this case frameworks such as Rails are the cause of the problem. Merging the two datatypes would most likely make such a huge different usage/code wise that it would probably be something for Ruby 5.0 (in other words, not in the near future). Yorick