Skip to content

Instantly share code, notes, and snippets.

@rishabg
Last active December 20, 2022 16:29
Show Gist options
  • Select an option

  • Save rishabg/d6e23ac1ad278cd71f765706e5bab3e0 to your computer and use it in GitHub Desktop.

Select an option

Save rishabg/d6e23ac1ad278cd71f765706e5bab3e0 to your computer and use it in GitHub Desktop.

Revisions

  1. rishabg revised this gist Dec 20, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions open_ended_perf.rb
    Original file line number Diff line number Diff line change
    @@ -6,14 +6,14 @@
    # Hint: There are multiple issues here. First try to list all of them before attempting possible solutions
    # Hint: Assume that the file is already present locally (ignore the network transfer process for the file)

    # As a final step: Discuss how you would go about investigating and improving: slow_process_that_updates_multiple_models
    # As a final step: Discuss how you would go about investigating and improving: slow_method_that_updates_multiple_models

    csv_file = CSV.parse(File.read(yuuge_csv_file), col_sep: self.separator, headers: true)
    ComplexModel.transaction do
    csv_file.each do |row|
    obj = ComplexModel.find(row[0])
    obj.children.each do |child|
    child.slow_process_that_updates_multiple_models(row)
    child.slow_method_that_updates_multiple_models(row)
    end
    end
    end
  2. rishabg created this gist Jan 20, 2017.
    19 changes: 19 additions & 0 deletions open_ended_perf.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # Discuss how you would speed this up Given that:
    # 1. CSV file can be very large
    # 2. Processing happens as within a webrequest (server timeout = 2 min)
    # 3. Not all optimizations are code-related. You are free to ask about possible functionality changes or side-effects.

    # Hint: There are multiple issues here. First try to list all of them before attempting possible solutions
    # Hint: Assume that the file is already present locally (ignore the network transfer process for the file)

    # As a final step: Discuss how you would go about investigating and improving: slow_process_that_updates_multiple_models

    csv_file = CSV.parse(File.read(yuuge_csv_file), col_sep: self.separator, headers: true)
    ComplexModel.transaction do
    csv_file.each do |row|
    obj = ComplexModel.find(row[0])
    obj.children.each do |child|
    child.slow_process_that_updates_multiple_models(row)
    end
    end
    end