Skip to content

Commit

Permalink
fix(performance): comment all log_debug
Browse files Browse the repository at this point in the history
  • Loading branch information
abrisse authored and gkellogg committed Apr 14, 2023
1 parent 742eecb commit 8d8cd36
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 103 deletions.
16 changes: 8 additions & 8 deletions lib/json/ld/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def self.compact(input, context, expanded: false, serializer: nil, **options)
end

API.new(expanded_input, context, no_default_base: true, **options) do
log_debug(".compact") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
# log_debug(".compact") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
result = compact(value)

# xxx) Add the given context to the output
Expand Down Expand Up @@ -290,7 +290,7 @@ def self.flatten(input, context, expanded: false, serializer: nil, **options)

# Initialize input using
API.new(expanded_input, context, no_default_base: true, **options) do
log_debug(".flatten") {"expanded input: #{value.to_json(JSON_STATE) rescue 'malformed json'}"}
# log_debug(".flatten") {"expanded input: #{value.to_json(JSON_STATE) rescue 'malformed json'}"}

# Rename blank nodes recusively. Note that this does not create new blank node identifiers where none exist, which is performed in the node map generation algorithm.
@value = rename_bnodes(@value) if @options[:rename_bnodes]
Expand Down Expand Up @@ -411,8 +411,8 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)

# Initialize input using frame as context
API.new(expanded_input, frame['@context'], no_default_base: true, **options) do
log_debug(".frame") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
log_debug(".frame") {"expanded frame: #{expanded_frame.to_json(JSON_STATE) rescue 'malformed json'}"}
# log_debug(".frame") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
# log_debug(".frame") {"expanded frame: #{expanded_frame.to_json(JSON_STATE) rescue 'malformed json'}"}

if %w(@first @last).include?(options[:embed]) && context.processingMode('json-ld-1.1')
raise JSON::LD::JsonLdError::InvalidEmbedValue, "#{options[:embed]} is not a valid value of @embed in 1.1 mode" if @options[:validate]
Expand Down Expand Up @@ -459,7 +459,7 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)

# Replace values with `@preserve` with the content of its entry.
result = cleanup_preserve(result)
log_debug(".frame") {"expanded result: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
# log_debug(".frame") {"expanded result: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}

# Compact result
compacted = compact(result)
Expand All @@ -478,7 +478,7 @@ def self.frame(input, frame, expanded: false, serializer: nil, **options)
# Only add context if one was provided
result = context.serialize(provided_context: frame).merge(result) if frame['@context']

log_debug(".frame") {"after compact: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
# log_debug(".frame") {"after compact: #{result.to_json(JSON_STATE) rescue 'malformed json'}"}
result
end

Expand Down Expand Up @@ -519,7 +519,7 @@ def self.toRdf(input, expanded: false, **options, &block)
API.new(flattened_input, nil, **options) do
# 1) Perform the Expansion Algorithm on the JSON-LD input.
# This removes any existing context to allow the given context to be cleanly applied.
log_debug(".toRdf") {"flattened input: #{flattened_input.to_json(JSON_STATE) rescue 'malformed json'}"}
# log_debug(".toRdf") {"flattened input: #{flattened_input.to_json(JSON_STATE) rescue 'malformed json'}"}

# Recurse through input
flattened_input.each do |node|
Expand All @@ -528,7 +528,7 @@ def self.toRdf(input, expanded: false, **options, &block)

# Drop invalid statements (other than IRIs)
unless statement.valid_extended?
log_debug(".toRdf") {"drop invalid statement: #{statement.to_nquads}"}
# log_debug(".toRdf") {"drop invalid statement: #{statement.to_nquads}"}
next
end

Expand Down
32 changes: 16 additions & 16 deletions lib/json/ld/compact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def compact(element,
base: nil,
property: nil,
log_depth: nil)
log_debug("compact", depth: log_depth.to_i) {"element: #{element.inspect}, ec: #{context.inspect}"}
# log_debug("compact", depth: log_depth.to_i) {"element: #{element.inspect}, ec: #{context.inspect}"}

# If the term definition for active property itself contains a context, use that for compacting values.
input_context = self.context

case element
when Array
#log_debug("") {"Array #{element.inspect}"}
# log_debug("") {"Array #{element.inspect}"}
result = element.map do |item|
compact(item, base: base, property: property, log_depth: log_depth.to_i + 1)
end.compact
Expand All @@ -38,10 +38,10 @@ def compact(element,
# member; otherwise the compacted value is element
if result.length == 1 &&
!context.as_array?(property) && @options[:compactArrays]
log_debug("=> extract single element", depth: log_depth.to_i) {result.first.inspect}
# log_debug("=> extract single element", depth: log_depth.to_i) {result.first.inspect}
result.first
else
log_debug("=> array result", depth: log_depth.to_i) {result.inspect}
# log_debug("=> array result", depth: log_depth.to_i) {result.inspect}
result
end
when Hash
Expand All @@ -52,7 +52,7 @@ def compact(element,

# Revert any previously type-scoped (non-preserved) context
if context.previous_context && !element.key?('@value') && element.keys != %w(@id)
log_debug("revert ec", depth: log_depth.to_i) {"previous context: #{context.previous_context.inspect}"}
# log_debug("revert ec", depth: log_depth.to_i) {"previous context: #{context.previous_context.inspect}"}
self.context = context.previous_context
end

Expand All @@ -61,13 +61,13 @@ def compact(element,
if td && !td.context.nil?
self.context = context.parse(td.context,
override_protected: true)
log_debug("prop-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
# log_debug("prop-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
end

if (element.key?('@id') || element.key?('@value')) && !element.key?('@annotation')
result = context.compact_value(property, element, base: @options[:base])
if !result.is_a?(Hash) || context.coerce(property) == '@json'
log_debug("", depth: log_depth.to_i) {"=> scalar result: #{result.inspect}"}
# log_debug("", depth: log_depth.to_i) {"=> scalar result: #{result.inspect}"}
return result
end
end
Expand All @@ -90,12 +90,12 @@ def compact(element,
each do |term|
term_context = input_context.term_definitions[term].context if input_context.term_definitions[term]
self.context = context.parse(term_context, propagate: false) unless term_context.nil?
log_debug("type-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
# log_debug("type-scoped", depth: log_depth.to_i) {"context: #{self.context.inspect}"}
end

element.keys.opt_sort(ordered: @options[:ordered]).each do |expanded_property|
expanded_value = element[expanded_property]
log_debug("", depth: log_depth.to_i) {"#{expanded_property}: #{expanded_value.inspect}"}
# log_debug("", depth: log_depth.to_i) {"#{expanded_property}: #{expanded_value.inspect}"}

if expanded_property == '@id'
compacted_value = as_array(expanded_value).map do |expanded_id|
Expand Down Expand Up @@ -134,7 +134,7 @@ def compact(element,
compacted_value = compact(expanded_value, base: base,
property: '@reverse',
log_depth: log_depth.to_i + 1)
log_debug("@reverse", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
# log_debug("@reverse", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
# handle double-reversed properties
compacted_value.each do |prop, value|
if context.reverse?(prop)
Expand All @@ -146,7 +146,7 @@ def compact(element,

unless compacted_value.empty?
al = context.compact_iri('@reverse', vocab: true)
log_debug("", depth: log_depth.to_i) {"remainder: #{al} => #{compacted_value.inspect}"}
# log_debug("", depth: log_depth.to_i) {"remainder: #{al} => #{compacted_value.inspect}"}
result[al] = compacted_value
end
next
Expand All @@ -157,7 +157,7 @@ def compact(element,
compacted_value = compact(expanded_value, base: base,
property: property,
log_depth: log_depth.to_i + 1)
log_debug("@preserve", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}
# log_debug("@preserve", depth: log_depth.to_i) {"compacted_value: #{compacted_value.inspect}"}

unless compacted_value.is_a?(Array) && compacted_value.empty?
result['@preserve'] = compacted_value
Expand All @@ -166,14 +166,14 @@ def compact(element,
end

if expanded_property == '@index' && context.container(property).include?('@index')
log_debug("@index", depth: log_depth.to_i) {"drop @index"}
# log_debug("@index", depth: log_depth.to_i) {"drop @index"}
next
end

# Otherwise, if expanded property is @direction, @index, @value, or @language:
if EXPANDED_PROPERTY_DIRECTION_INDEX_LANGUAGE_VALUE.include?(expanded_property)
al = context.compact_iri(expanded_property, vocab: true)
log_debug(expanded_property, depth: log_depth.to_i) {"#{al} => #{expanded_value.inspect}"}
# log_debug(expanded_property, depth: log_depth.to_i) {"#{al} => #{expanded_value.inspect}"}
result[al] = expanded_value
next
end
Expand Down Expand Up @@ -223,7 +223,7 @@ def compact(element,
compacted_item = compact(value, base: base,
property: item_active_property,
log_depth: log_depth.to_i + 1)
log_debug("", depth: log_depth.to_i) {" => compacted key: #{item_active_property.inspect} for #{compacted_item.inspect}"}
# log_debug("", depth: log_depth.to_i) {" => compacted key: #{item_active_property.inspect} for #{compacted_item.inspect}"}

# handle @list
if list?(expanded_item)
Expand Down Expand Up @@ -345,7 +345,7 @@ def compact(element,
result
else
# For other types, the compacted value is the element value
log_debug("compact", depth: log_depth.to_i) {element.class.to_s}
# log_debug("compact", depth: log_depth.to_i) {element.class.to_s}
element
end

Expand Down

0 comments on commit 8d8cd36

Please sign in to comment.