Route params no longer symbols

閲覧: 33 回
最初の未読メッセージにスキップ

Adam Meehan

未読、
2008/04/02 1:51:002008/04/02
To: sinatrarb
Hi,

Just getting into using Sinatra and playing around. Thanks for great
work.

Using the current master branch README as the current guide I was
tripped up by the route params now being string keys and not symbols
in the params hash.

I noticed your log entry mentioned that symbols are not garbage
collected as the reason to move to string keys. But I find that the
use of the symbol syntax in the route and then using a string key in
the params hash grates somewhat.

Given that symbols are reused once defined, I would have thought that
the amount of symbols used in route params for typical Sinatra app
would be small and add little memory overhead.

Is this not what you have found?

Adam

Blake Mizerany

未読、
2008/04/02 3:36:252008/04/02
To: sina...@googlegroups.com
Adam,

It's about 2 things:

  1.  Converting every params hash to symbolize slows down request times.  Not a biggie for most of us but a benifit of not using them
  2.  Because symbols are not garbage collected, blindly symbolizing keys means that your open to an attack where someone sends random params keys and eats up memory.  

I'm looking into another way to get them back without using the bulky HWIA.

Please let me know any ideas.

-blake
--
Blake Mizerany
blake.m...@gmail.com

Adam Meehan

未読、
2008/04/02 4:14:182008/04/02
To: sinatrarb
Thanks Blake.

1. Given the intended use for Sinatra I certainly understand the speed
bias.

2. Interesting point. I wonder what Rails does. Will have a look.

Agreed HWIA would nice to avoid.

Cheers,
Adam.
> blake.mizer...@gmail.com

Blake Mizerany

未読、
2008/04/02 14:37:252008/04/02
To: sina...@googlegroups.com
Rails uses HWIA.
--
Blake Mizerany
blake.m...@gmail.com

Adam Meehan

未読、
2008/04/02 16:24:222008/04/02
To: sinatrarb
Yes of course. derr!
> blake.mizer...@gmail.com

Jeremy Evans

未読、
2008/04/03 17:47:532008/04/03
To: sinatrarb
On Apr 2, 12:36 am, "Blake Mizerany" <blake.mizer...@gmail.com> wrote:
> Adam,
> It's about 2 things:
>
> 1. Converting every params hash to symbolize slows down request times.
> Not a biggie for most of us but a benifit of not using them
> 2. Because symbols are not garbage collected, blindly symbolizing keys
> means that your open to an attack where someone sends random params keys and
> eats up memory.
>
> I'm looking into another way to get them back without using the bulky HWIA.
>
> Please let me know any ideas.

You can get a cheap version of a hash that accepts symbols without
HWIA:

hwia = Hash.new{|h,k| h[k.to_s] if Symbol === k}

Jeremy

Blake Mizerany

未読、
2008/04/03 22:57:202008/04/03
To: sina...@googlegroups.com
sweet. I'll get that in.  thx
--
Blake Mizerany
blake.m...@gmail.com

Blake Mizerany

未読、
2008/04/08 19:42:282008/04/08
To: sina...@googlegroups.com
K.  Symbol params are back in thanks to Jeremy and his helpful tidbit.

http://github.com/bmizerany/sinatra/commit/98572b4d0d406c7f1e7a1d9100887c4b2fb07f9e

On Thu, Apr 3, 2008 at 2:47 PM, Jeremy Evans <jeremy...@gmail.com> wrote:



--
Blake Mizerany
blake.m...@gmail.com

Adam Meehan

未読、
2008/04/08 19:46:462008/04/08
To: sinatrarb
Good work. Thanks Jeremy!

On Apr 9, 9:42 am, "Blake Mizerany" <blake.mizer...@gmail.com> wrote:
> K. Symbol params are back in thanks to Jeremy and his helpful tidbit.
>
> http://github.com/bmizerany/sinatra/commit/98572b4d0d406c7f1e7a1d9100...
>
>
>
> On Thu, Apr 3, 2008 at 2:47 PM, Jeremy Evans <jeremyeva...@gmail.com> wrote:
>
> > On Apr 2, 12:36 am, "Blake Mizerany" <blake.mizer...@gmail.com> wrote:
> > > Adam,
> > > It's about 2 things:
>
> > > 1. Converting every params hash to symbolize slows down request
> > times.
> > > Not a biggie for most of us but a benifit of not using them
> > > 2. Because symbols are not garbage collected, blindly symbolizing
> > keys
> > > means that your open to an attack where someone sends random params keys
> > and
> > > eats up memory.
>
> > > I'm looking into another way to get them back without using the bulky
> > HWIA.
>
> > > Please let me know any ideas.
>
> > You can get a cheap version of a hash that accepts symbols without
> > HWIA:
>
> > hwia = Hash.new{|h,k| h[k.to_s] if Symbol === k}
>
> > Jeremy
>
> --
> Blake Mizerany
> blake.mizer...@gmail.com
全員に返信
投稿者に返信
転送
新着メール 0 件