Skip to content

Commit e2d13ef

Browse files
Improved caching to improve performance of test:regress by about 2X. (#670)
1 parent 4a58b59 commit e2d13ef

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

lib/arch_obj_models/extension.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,11 @@ def invert!
495495

496496
# @return [Array<ExtensionVersion>] The list of extension versions that satisfy this extension requirement
497497
def satisfying_versions
498+
return @satisfying_versions unless @satisfying_versions.nil?
499+
498500
ext = @arch.extension(@name)
499-
return [] if ext.nil?
500501

501-
ext.versions.select { |v| satisfied_by?(v) }
502+
@satisfying_versions = ext.nil? ? [] : ext.versions.select { |v| satisfied_by?(v) }
502503
end
503504

504505
# @return [ExtensionVersion] The minimum extension version that satifies this extension requirement.

lib/arch_obj_models/portfolio.rb

+34-16
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ def extension_presence(ext_name)
385385
# @return [Presence] Given an instruction +inst_name+, return the presence.
386386
# If the instruction name isn't found in the portfolio, return nil.
387387
def instruction_presence_obj(inst_name)
388+
@instruction_presence_obj ||= {}
389+
390+
return @instruction_presence_obj[inst_name] unless @instruction_presence_obj[inst_name].nil?
391+
388392
inst = arch.instruction(inst_name)
389393

390394
raise "Can't find instruction object '#{inst_name}' in arch class" if inst.nil?
@@ -399,26 +403,35 @@ def instruction_presence_obj(inst_name)
399403
ext_versions.any? { |ext_ver| inst.defined_by_condition.possibly_satisfied_by?(ext_ver) }
400404
end
401405

402-
if is_mandatory
403-
Presence.new(Presence.mandatory)
404-
elsif is_optional
405-
Presence.new(Presence.optional)
406-
else
407-
nil
408-
end
406+
@instruction_presence_obj[inst_name] =
407+
if is_mandatory
408+
Presence.new(Presence.mandatory)
409+
elsif is_optional
410+
Presence.new(Presence.optional)
411+
else
412+
nil
413+
end
409414
end
410415

411416
# @return [String] Given an instruction +inst_name+, return the presence as a string.
412417
# If the instruction name isn't found in the portfolio, return "-".
413418
def instruction_presence(inst_name)
419+
@instruction_presence ||= {}
420+
421+
return @instruction_presence[inst_name] unless @instruction_presence[inst_name].nil?
422+
414423
presence_obj = instruction_presence_obj(inst_name)
415424

416-
presence_obj.nil? ? "-" : presence_obj.to_s
425+
@instruction_presence[inst_name] = presence_obj.nil? ? "-" : presence_obj.to_s
417426
end
418427

419428
# @return [Presence] Given an CSR +csr_name+, return the presence.
420429
# If the CSR name isn't found in the portfolio, return nil.
421430
def csr_presence_obj(csr_name)
431+
@csr_presence_obj ||= {}
432+
433+
return @csr_presence_obj[csr_name] unless @csr_presence_obj[csr_name].nil?
434+
422435
csr = arch.csr(csr_name)
423436

424437
raise "Can't find CSR object '#{csr_name}' in arch class" if csr.nil?
@@ -433,21 +446,26 @@ def csr_presence_obj(csr_name)
433446
ext_versions.any? { |ext_ver| csr.defined_by_condition.possibly_satisfied_by?(ext_ver) }
434447
end
435448

436-
if is_mandatory
437-
Presence.new(Presence.mandatory)
438-
elsif is_optional
439-
Presence.new(Presence.optional)
440-
else
441-
nil
442-
end
449+
@csr_presence_obj[csr_name] =
450+
if is_mandatory
451+
Presence.new(Presence.mandatory)
452+
elsif is_optional
453+
Presence.new(Presence.optional)
454+
else
455+
nil
456+
end
443457
end
444458

445459
# @return [String] Given an CSR +csr_name+, return the presence as a string.
446460
# If the CSR name isn't found in the portfolio, return "-".
447461
def csr_presence(csr_name)
462+
@csr_presence ||= {}
463+
464+
return @csr_presence[csr_name] unless @csr_presence[csr_name].nil?
465+
448466
presence_obj = csr_presence_obj(csr_name)
449467

450-
presence_obj.nil? ? "-" : presence_obj.to_s
468+
@csr_presence[csr_name] = presence_obj.nil? ? "-" : presence_obj.to_s
451469
end
452470

453471
# Returns the greatest presence string for each of the specified versions.

lib/cfg_arch.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def transitive_implemented_csrs
636636

637637
# @return [Array<Csr>] List of all CSRs that it is possible to implement
638638
def not_prohibited_csrs
639-
@not_prohibited_csrs =
639+
@not_prohibited_csrs ||=
640640
if @config.fully_configured?
641641
transitive_implemented_csrs
642642
elsif @config.partially_configured?

0 commit comments

Comments
 (0)