weixin_39560604
weixin_39560604
2021-01-06 21:23

Huge refactoring

Do not create huge strings Let SimpleTypedList inherit from Array Let Row inherit from SimpleTypedList Optimized sanitizing Optimized validation And more..

The parentheses around the << calls are because of the following bug in ruby-zip: using chained #<< will create a damaged zip file. They can be removed after ruby-zip is fixed.

该提问来源于开源项目:randym/axlsx

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • weixin_39560604 weixin_39560604 4月前

    There are still things to optimise: (~4 Arrays per Cell and ~16 Strings per Cell are allocated at the moment)

    screen shot 2014-02-26 at 23 17 33

     ruby
    require 'axlsx'
    require 'allocation_stats'
    a = AllocationStats.new(burn: 2)
    stats = a.trace do
      Axlsx::Package.new do |p|
        p.workbook.add_worksheet(:name => "Test") do |sheet|
          some_number.times do
              sheet.add_row ["test data"] * 60
          end
        end
        p.serialize('test.xlsx')
      end
    end
    puts stats.allocations(alias_paths: true).group_by(:class).to_text
    
    点赞 评论 复制链接分享
  • weixin_39867594 weixin_39867594 4月前

    Sorry for the short version! 1. You are awesome for taking this on! 2. I'm not a fan of inheriting from Array. For me the cost of allocating the object is less than then double lookup - but I'm happy to be proven wrong! 3. 1.9.2 is still supported so extend string as you need to to bring it in line with later versions. 4. How do the benchmarks look on this? Any reduction in GC?

    点赞 评论 复制链接分享
  • weixin_39560604 weixin_39560604 4月前

    To be honest, this thing started as an experiment and has grown way too big.. On my system I see a reduction of ~ 50% in certain cases (the heapsize is increased 2 times less during serialising). I also did a memory dump and inspected it and came to the conclusion that the Ruby GC is not very efficient in combination with Axlsx, lots of useless strings duplicated numerous times... If I have some time I'll take a look at it again and see if I can optimise it :) I don't have to much time for it now, but how do we get this in axlsx? Should I split it in a few smaller pull requests?

    点赞 评论 复制链接分享
  • weixin_39867594 weixin_39867594 4月前

    Impressive!!

    The only thing I would even dare to ask is that the String#prepend method is injected in an efficient way where not defined and the specs pass on travis for the required matrix.

    I've given you commit privileges on this repo for a reason - I trust your work! Don't be afraid to make changes, be daring - even to totally screwup master. We will sort it out if/when we need to.

    点赞 评论 复制链接分享
  • weixin_39560604 weixin_39560604 4月前

    Thanks for you trust! I'm going to merge it after I've solved the conflicts with current master :)

    点赞 评论 复制链接分享
  • weixin_39867594 weixin_39867594 4月前

    That smells like AWESOMENESS to me!

    点赞 评论 复制链接分享
  • weixin_39560604 weixin_39560604 4月前

    Looks like rubinius still has some problems.. :-1:

    点赞 评论 复制链接分享
  • weixin_39560604 weixin_39560604 4月前

    Fixed it, hopefully ruby zip will do something with my issue, or I'll have to create a pull request there.. Putting all those statements between parentheses is not a very nice solution.

    I've reverted the 'SimpleTypedList inherit from Array' because it also caused the rubinius issues.

    点赞 评论 复制链接分享

相关推荐