# Ruby Hash/Array to\_yaml is slow

**URL:** <https://www.ruby-forum.com/t/ruby-hash-array-to-yaml-is-slow/136536>\
**Category:** Ruby\
**Created:** [May 3, 2008, 7:57am UTC](https://www.ruby-forum.com/t/ruby-hash-array-to-yaml-is-slow/136536 "2008-05-03T07:57:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [May 3, 2008, 7:57am UTC](https://www.ruby-forum.com/t/ruby-hash-array-to-yaml-is-slow/136536/1 "2008-05-03T07:57:53Z")

</div>

I try to convert a ruby array(contains hash and array) to yaml and it  
takes 60 seconds to perform the job and it consumes a lot of memory and  
full cpu usage(almost 100%). The ruby object is very big and it will  
produce 80000+ lines of yaml file. The speed is not acceptable for me.  
So, instead of using the to\_yaml function I created my own conversion  
function just do print string for the hash and the array and now it only  
take 2 seconds.(I did some changes like use inner hash to reduce the  
yaml lines count, now it only produce 40000 lines) I am not sure the  
alogrithm of the yaml but could it be a bug for the ruby yaml?

---

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [May 3, 2008, 10:12pm UTC](https://www.ruby-forum.com/t/ruby-hash-array-to-yaml-is-slow/136536/2 "2008-05-03T22:12:33Z")

</div>

On May 2, 2008, at 22:57 , Shin guey Wong wrote:

> I am not sure the  
> alogrithm of the yaml but could it be a bug for the ruby yaml?

if it is, this isn’t the right forum to report it. File a bug on  
\_why’s trac.

Alternatively, use Marshal.
