Expression bound to unused variable still evaluated

Bug #1204362 reported by Chris Hillery
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Zorba
Fix Committed
Medium
Markos Zaharioudakis

Bug Description

import module namespace http = "http://www.zorba-xquery.com/modules/http-client";
import module namespace file = "http://expath.org/ns/file";
import module namespace x = "http://www.zorba-xquery.com/modules/xml";
import schema namespace opt = "http://www.zorba-xquery.com/modules/xml-options";

let $xml-frags1 := x:parse(file:read-text(fn:resolve-uri("levels.xml")),
<opt:options>
<opt:parse-external-parsed-entity/>
</opt:options>)

let $xml-frags2 := <a></a>

return $xml-frags2

(I will attach levels.xml, but its contents are not actually relevant I don't believe.)

Run this query, redirecting the output of Zorba to /dev/null to skip the time it takes to write the output. Then change "return $xml-frags2" to "return $xml-frags1" and run it again. You will see two things:

1. Both queries take basically identical lengths of time to run.
2. When running the first query, memory consumption ramps up throughout the execution, whereas with the second query memory stays at a consistent low point.

This implies two problems:

A. Zorba isn't skipping the evaluation of x:parse(file:read-text(...)), even though the result is assigned to a variable that is not used later in the query.

B. In that case, Zorba is actually parsing *and materializing* the input XML.

Fixing (A) would make (B) moot, but I really think we should understand why (B) is happening because it seems awfully strange.

Chris Hillery (ceejatec)
Changed in zorba:
assignee: nobody → Markos Zaharioudakis (markos-za)
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Chris Hillery (ceejatec) wrote :

Initial bug report and some follow-up discussion:

https://groups.google.com/forum/#!msg/zorba-users/f7YRINPw-A8/GeYmzblJVj0J

Revision history for this message
Chris Hillery (ceejatec) wrote :
Chris Hillery (ceejatec)
summary: - Compiler doesn't always eliminate unused code
+ Expression bound to unused variable still evaluated
Changed in zorba:
milestone: none → 3.0
Chris Hillery (ceejatec)
Changed in zorba:
importance: High → Medium
Changed in zorba:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.