Re: Memory allocation overhead

Colin Paul Adams <[email protected]>
Newsgroups gmane.comp.lang.eiffel.gobo.devel
Message-ID <[email protected]>
>>>>> "Colin" == Colin Paul Adams <[email protected]> writes:

    Colin> I am currently trying this with the iterators used to
    Colin> evaluate XPath sequences. I am retaining copies on a once
    Colin> DS_ARRAYED_STACK. So far, this is actually increasing the
    Colin> runtime (but it appears sensitive to the size of the stack,
    Colin> so I am currently trying with just a DS_CELL to see if this
    Colin> is better).

In fact the DS_CELL proved to be slower than a small stack.

But I am now wondering about code inlining. It appears that gec does
not inline all three routines new_child_tree_iterator, release_iterator
and new_descendant_tree_iterator in the code below. (Note that the bulk of
the class is commented out. The test program then runs in 21 minutes
and 8 seconds, as opposed to 20 minutes and 28 seconds (+- 3 seconds)
with the creations inlined, and no call to release_iterator (there is
an extra assignment to Void of the iterator passed to release_iterator
following the call to release_iterator, but I hardly think that can
account for the difference). With all the commented-out code restored,
(and assignemt of 4 default values to attributes in the creation
procedures, which costs about 6 seconds) the time rises to 21 minutes
and 52 seconds. 

I can't account for any of this.


class XM_XPATH_ITERATOR_POOL

feature -- Creation

	new_child_tree_iterator (a_starting_node: XM_XPATH_TREE_NODE; a_node_test: XM_XPATH_NODE_TEST): XM_XPATH_TREE_CHILD_ENUMERATION is
			-- New or reused child iterator for `a_starting_node'
		require
			starting_node_not_void: a_starting_node /= Void
			node_test_not_void: a_node_test /= Void
		do
--			if child_tree_iterators.is_empty then
				create Result.make (a_starting_node, a_node_test)
--			else
--				Result := child_tree_iterators.item
--				Result.make (a_starting_node, a_node_test)
--				child_tree_iterators.remove
--			end
		ensure
			new_child_tree_iterator_not_void: Result /= Void
		end

	new_descendant_tree_iterator (a_starting_node: XM_XPATH_TREE_NODE; a_node_test: XM_XPATH_NODE_TEST;
		a_include_self: BOOLEAN): XM_XPATH_TREE_DESCENDANT_ENUMERATION is
			-- New or reused descendant iterator for `a_starting_node'
		require
			starting_node_not_void: a_starting_node /= Void
			node_test_not_void: a_node_test /= Void
		do
--			if descendant_tree_iterators.is_empty then
				create Result.make (a_starting_node, a_node_test, a_include_self)
--			else
--				Result := descendant_tree_iterators.item
--				Result.make (a_starting_node, a_node_test, a_include_self)
--				descendant_tree_iterators.remove
--			end
		ensure
			new_descendant_tree_iterator_not_void: Result /= Void
		end
			
feature -- Removal

	release_iterator (a_iterator: XM_XPATH_SEQUENCE_ITERATOR [XM_XPATH_ITEM]) is
			-- Return `a_iterator' to free memory.
		require
			a_iterator_not_void: a_iterator /= Void
		do
--			if a_iterator.is_tree_child_enumeration then
--				if child_tree_iterators.count < Maximum_queue_length then
--					child_tree_iterators.put (a_iterator.as_tree_child_enumeration)
--				end
--			elseif a_iterator.is_tree_descendant_enumeration then
--				if descendant_tree_iterators.count < Maximum_queue_length then
--					descendant_tree_iterators.put (a_iterator.as_tree_descendant_enumeration)
--				end
--			end
		end

feature {NONE} -- Implementation

	Maximum_queue_length: INTEGER is 5
			-- Limit on queue size for any single iterator type

--	child_tree_iterators: DS_ARRAYED_STACK [XM_XPATH_TREE_CHILD_ENUMERATION]
--			-- Spare iterators over the child axis of XM_XPATH_TREE_NODEs
--		once
--			create Result.make (Maximum_queue_length)
--		ensure
--			child_tree_iterators_not_void: Result /= Void
--		end

--	descendant_tree_iterators: DS_ARRAYED_STACK [XM_XPATH_TREE_DESCENDANT_ENUMERATION]
--			-- Spare iterators over the descendant axis of XM_XPATH_TREE_NODEs
--		once
--			create Result.make (Maximum_queue_length)
--		ensure
--			descendant_tree_iterators_not_void: Result /= Void
--		end

end

-- 
Colin Adams
Preston Lancashire

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.