Forum: Ruby-core [ruby-trunk - Feature #9143][Open] Optimize CSV to share hash key objects between rows

F0987c97234fa9c6b26f796bdbdab037?d=identicon&s=25 avit (Andrew Vit) (Guest)
on 2013-11-22 21:06
(Received via mailing list)
Issue #9143 has been reported by avit (Andrew Vit).

----------------------------------------
Feature #9143: Optimize CSV to share hash key objects between rows
https://bugs.ruby-lang.org/issues/9143

Author: avit (Andrew Vit)
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version:


Currently, when CSV headers are strings, then each row receives a copy
of the strings for hash keys. This patch is an optimization to share the
same frozen string keys between all rows.

Please verify: in the implementation of `Hash::[]`, are strings the only
object that is dup'd, or should other types be frozen so they aren't
copied for each row too?
F0987c97234fa9c6b26f796bdbdab037?d=identicon&s=25 avit (Andrew Vit) (Guest)
on 2013-11-22 21:41
(Received via mailing list)
Issue #9143 has been updated by avit (Andrew Vit).


Note, this can be worked around by doing `csv.header_converters <<
proc{|h| h.freeze }` but I think there should be some built-in
optimization for this.
----------------------------------------
Feature #9143: Optimize CSV to share hash key objects between rows
https://bugs.ruby-lang.org/issues/9143#change-43092

Author: avit (Andrew Vit)
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version:


Currently, when CSV headers are strings, then each row receives a copy
of the strings for hash keys. This patch is an optimization to share the
same frozen string keys between all rows.

Please verify: in the implementation of `Hash::[]`, are strings the only
object that is dup'd, or should other types be frozen so they aren't
copied for each row too?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-11-23 16:56
(Received via mailing list)
Issue #9143 has been updated by nobu (Nobuyoshi Nakada).


You can use assert_instance_of and assert_same.
----------------------------------------
Feature #9143: Optimize CSV to share hash key objects between rows
https://bugs.ruby-lang.org/issues/9143#change-43112

Author: avit (Andrew Vit)
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version:


Currently, when CSV headers are strings, then each row receives a copy
of the strings for hash keys. This patch is an optimization to share the
same frozen string keys between all rows.

Please verify: in the implementation of `Hash::[]`, are strings the only
object that is dup'd, or should other types be frozen so they aren't
copied for each row too?
F0987c97234fa9c6b26f796bdbdab037?d=identicon&s=25 avit (Andrew Vit) (Guest)
on 2013-11-24 00:36
(Received via mailing list)
Issue #9143 has been updated by avit (Andrew Vit).

File csv-freeze-headers-2.patch added

Thanks nobu, I write too much RSpec lately.

Updated patch attached: I also added freeze in Row#initialize, not sure
if both places are needed, or which is better. Please review.
----------------------------------------
Feature #9143: Optimize CSV to share hash key objects between rows
https://bugs.ruby-lang.org/issues/9143#change-43122

Author: avit (Andrew Vit)
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version:


Currently, when CSV headers are strings, then each row receives a copy
of the strings for hash keys. This patch is an optimization to share the
same frozen string keys between all rows.

Please verify: in the implementation of `Hash::[]`, are strings the only
object that is dup'd, or should other types be frozen so they aren't
copied for each row too?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-11-24 01:01
(Received via mailing list)
Issue #9143 has been updated by nobu (Nobuyoshi Nakada).


assert_predicate(string_key, :frozen?) will show better message when it
fails.
----------------------------------------
Feature #9143: Optimize CSV to share hash key objects between rows
https://bugs.ruby-lang.org/issues/9143#change-43123

Author: avit (Andrew Vit)
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version:


Currently, when CSV headers are strings, then each row receives a copy
of the strings for hash keys. This patch is an optimization to share the
same frozen string keys between all rows.

Please verify: in the implementation of `Hash::[]`, are strings the only
object that is dup'd, or should other types be frozen so they aren't
copied for each row too?
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-11-24 01:02
(Received via mailing list)
Issue #9143 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Open to Assigned
Assignee set to JEG2 (James Gray)


----------------------------------------
Feature #9143: Optimize CSV to share hash key objects between rows
https://bugs.ruby-lang.org/issues/9143#change-43124

Author: avit (Andrew Vit)
Status: Assigned
Priority: Normal
Assignee: JEG2 (James Gray)
Category: lib
Target version:


Currently, when CSV headers are strings, then each row receives a copy
of the strings for hash keys. This patch is an optimization to share the
same frozen string keys between all rows.

Please verify: in the implementation of `Hash::[]`, are strings the only
object that is dup'd, or should other types be frozen so they aren't
copied for each row too?
8192b1cea9add09ee359336dea28a85f?d=identicon&s=25 JEG2 (James Gray) (Guest)
on 2013-11-24 01:47
(Received via mailing list)
Issue #9143 has been updated by JEG2 (James Gray).

Status changed from Assigned to Closed
% Done changed from 50 to 100


----------------------------------------
Feature #9143: Optimize CSV to share hash key objects between rows
https://bugs.ruby-lang.org/issues/9143#change-43125

Author: avit (Andrew Vit)
Status: Closed
Priority: Normal
Assignee: JEG2 (James Gray)
Category: lib
Target version:


Currently, when CSV headers are strings, then each row receives a copy
of the strings for hash keys. This patch is an optimization to share the
same frozen string keys between all rows.

Please verify: in the implementation of `Hash::[]`, are strings the only
object that is dup'd, or should other types be frozen so they aren't
copied for each row too?
This topic is locked and can not be replied to.