Re: [basex-talk] Importing XML (DITA) validated with Relax NG schemas?

2018-10-17 Thread Christian Grün
Hi Radu,

Do you think the DITA parsing should work if dita-ng.jar is placed first in
the classpath?

Cheers,
Christian




Jason Davis  schrieb am Mo., 15. Okt. 2018,
17:46:

> Hi Christian, Radu,
>
> I’ve tried adding the dita-ng.jar to the lib/custom dir of basex and then
> manually modified the startup script to load it first. I can even confirm
> that it’s the first jar on the path using:
>
> proc:property('java.class.path')
>
> However, the database still fails to parse the XML with default attributes
> applied. I find myself having to cobble together an undesirable workaround
> whereby I manually supply the default attribute values myself in order to
> get my project to work with BaseX. Do you have any further suggestions for
> how I might get this to work?
>
> Thanks,
> Jason
>
> On 10/3/18, 3:24 AM, "Christian Grün"  wrote:
>
> Hi Jason (cc to the list),
>
> > I set the CP variable like so:
> >
> CP=$MAIN/BaseX.jar:$MAIN/lib/custom/dita-ng.jar:$MAIN/lib/*:$MAIN/lib/custom/*:$CLASSPATH
> >
> > This appears to be slightly different than the example you linked
> Christian. I’m using BaseX 9.0.2. Does this make a difference?
>
> The start scripts in the official distributions are created from the
> GitHub examples I linked, so they are slightly different.
>
> > I added an echo $CLASSPATH line under the CP variable. When I run
> the script, the echo statement is blank.
>
> In the script, no value will be bound to the $CLASSPATH variable.
> Instead, you can assign values to this variable by yourself, which
> will then be appended to the $CP variable. If you didn’t do so, and if
> your Linux environment does not have any other values assigned to this
> variable (which is the default), the output will necessarily be empty.
>
> > Is there a way to see how the classpath is set when running this
> script?
>
> To answer the "how": It will be set via the line that you will find
> some lines below in the script, and the -cp Java argument:
>
>   exec java -cp "$CP" $BASEX_JVM org.basex.BaseX "$@"
>
> If you want to know which value is bound to $CP, try "echo $CP". In
> Java, the full user class path at runtime will be bound to the
> "java.class.path" system property. It can e.g. be retrieved via
> proc:property('java.class.path') [1].
>
> Christian
>
> [1] http://docs.basex.org/wiki/Process_Module#proc:property
>
>
>
>


Re: [basex-talk] Reflect.forName() / Performance

2018-10-17 Thread Tom Rauchenwald
Hi Christian,

thanks for your feedback, I hope you're doing well!

> I have some concerns that the caching of non-existing classes could be
> exploited and bloat the cache. Maybe we’d need to use WeakHashMap
> (and/or soft references) instead?

I didn't think about that, I'll try to come up with a better solution.

>> I'm not sure why BaseX tries to load our xqm as Java Modules, but
>> what I noticed is that Reflect.forName caches the positive case
>> (i.e., the class is found), but not the negative case (i.e., the class is 
>> not found).
>
> Sounds like an interesting finding; maybe there’s something we can
> optimize here. Could you possibly provide us a little self-contained
> example that demonstrates the behavior?

Sure. This is what I'm doing:

Given the following module (installed with module install foo.xqm):

module namespace uc = 'http://unifits.com/common';
declare function uc:remove-elements($input as element(), $remove-names as 
xs:string*) as element() {
  element {node-name($input) }
  {$input/@*,
for $child in $input/node()[not(local-name() = $remove-names)]
return
  if ($child instance of element())
  then uc:remove-elements($child, $remove-names)
  else $child
   }
};


if I start BaseXGui in debug mode, and set a breakpoint in
Reflect.forName(), every time I execute a query such as

import module namespace uc = 'http://unifits.com/common';
/

the breakpoint is hit, i.e. Class.forName() is called. 
I *think* this might have to do with the fact that the function above is
recursive, but I have to admit that I don't really grasp the code that
does the module loading/parsing.

Thanks,
-tom



Re: [basex-talk] Reflect.forName() / Performance

2018-10-17 Thread Christian Grün
Hi Tom,

Thanks for your observation and your code proposal; always welcome.

I have some concerns that the caching of non-existing classes could be
exploited and bloat the cache. Maybe we’d need to use WeakHashMap
(and/or soft references) instead?

> I'm not sure why BaseX tries to load our xqm as Java Modules, but what I 
> noticed is that Reflect.forName caches the positive case (i.e., the class is 
> found), but not the negative case (i.e., the class is not found).

Sounds like an interesting finding; maybe there’s something we can
optimize here. Could you possibly provide us a little self-contained
example that demonstrates the behavior?

Thanks in advance,
Christian



On Wed, Oct 17, 2018 at 9:53 AM Tom Rauchenwald (UNIFITS)
 wrote:
>
> Hi BaseX-Team,
>
>
> when profiling some of our tests i found that we spend some time in 
> Reflect.forName().
>
> We have 2 xquery modules in the repo (we don't call java code directly).
>
>
> I'm not sure why BaseX tries to load our xqm as Java Modules, but what I 
> noticed is that Reflect.forName caches the positive case (i.e., the class is 
> found), but not the negative case (i.e., the class is not found).
>
> I've changed the code to cache the negative case as well (see below), and 
> noticed an improvement of about 5 percent.
>
> Our tests create and query loads of small databases, so this is maybe quite 
> an artificial speedup.
>
>
> I could provide a PR if this is a worthwhile improvement in your opinion (and 
> if I'm not missing something obvious).
>
>
> We're still on BaseX 8.7.6 in case that matters, as far as I could see the 
> Code didn't change in BaseX 9.
>
>
> Thanks,
>
> Tom
>
>
> Code:
>
>
> public static Class forName(final String name) throws 
> ClassNotFoundException {
> Class c = CLASSES.get(name);
>
> if(c == null) {
>   if (CLASSES.containsKey(name)) {
> throw new ClassNotFoundException(name);
>   } else {
> try {
>   c = Class.forName(name);
> } catch (ClassNotFoundException e) {
>   CLASSES.put(name, null);
>   throw e;
> }
> if (!Modifier.isPublic(c.getModifiers())) throw new 
> ClassNotFoundException(name);
> CLASSES.put(name, c);
>   }
> }
> return c;
>   }
>


[basex-talk] Reflect.forName() / Performance

2018-10-17 Thread Tom Rauchenwald (UNIFITS)
Hi BaseX-Team,


when profiling some of our tests i found that we spend some time in 
Reflect.forName().

We have 2 xquery modules in the repo (we don't call java code directly).


I'm not sure why BaseX tries to load our xqm as Java Modules, but what I 
noticed is that Reflect.forName caches the positive case (i.e., the class is 
found), but not the negative case (i.e., the class is not found).

I've changed the code to cache the negative case as well (see below), and 
noticed an improvement of about 5 percent.

Our tests create and query loads of small databases, so this is maybe quite an 
artificial speedup.


I could provide a PR if this is a worthwhile improvement in your opinion (and 
if I'm not missing something obvious).


We're still on BaseX 8.7.6 in case that matters, as far as I could see the Code 
didn't change in BaseX 9.


Thanks,

Tom


Code:


public static Class forName(final String name) throws ClassNotFoundException 
{
Class c = CLASSES.get(name);

if(c == null) {
  if (CLASSES.containsKey(name)) {
throw new ClassNotFoundException(name);
  } else {
try {
  c = Class.forName(name);
} catch (ClassNotFoundException e) {
  CLASSES.put(name, null);
  throw e;
}
if (!Modifier.isPublic(c.getModifiers())) throw new 
ClassNotFoundException(name);
CLASSES.put(name, c);
  }
}
return c;
  }