From: Humbel O. <Otm...@bi...> - 2002-01-10 09:30:22
|
[ Prathibha ] > I currently use python code(jython actually) which I > retrieve from the DB to compile and interpret it at > runtime. Will using precompiled python scripts in the > DB improve performance significantly? I am asking this > as I am also looking to caching these precompiled > scripts to improve performance as well. That's exactly the way we do it: - the database contains the .py code (as clob) - we use a runtime cache containing precompiled code=20 for the most used scripts This improves performance considerably (I'm sorry I can't give you a percentage - I simply don't know). Below I try to sketch how we do the precompiling.=20 ATTN: This may not be state of the art. I would be really glad if someone knows a better(*) way to do it. Server code: ByteArrayOutputStream outputStream =3D=20 new ByteArrayOutputStream(); ByteArrayInputStream sourceCode =3D=20 new ByteArrayInputStream( scriptData ); String uniqueID =3D "org.python.pycode._py" + scriptID; SimpleNode node =3D=20 parser.parse( sourceCode, "exec", uniqueID, null ); Module.compile( node, outputStream , name, filename,=20 true, false, false, null ); byte[] byteCode =3D outputStream.toByteArray(); This byte array can be transferred from server to client. On the client we make runnable code out of it: byte[] byteCode =3D getByteCodeFromServer( scriptID); String uniqueID =3D "org.python.pycode._py" + scriptID; PyCode currentCode =3D=20 BytecodeLoader.makeCode( uniqueID, byteCode ); and run it as follows: PyObject result =3D Py.runCode( currentCode, locals, globals ); Hopefully this gives you some ideas. I also would also appreciate it if someone knows a better(*) way to precompile if everything takes place in the same JVM. Best wishes, and thanks in advance. Oti. Legend: ------- (*) better: more upwards compatible, more performant more elegant .... |