You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by "Ostrzyciel (via GitHub)" <gi...@apache.org> on 2024/10/26 11:08:29 UTC

[PR] GH-2797: Lazy init for ValidationState hash maps [jena]

Ostrzyciel opened a new pull request, #2798:
URL: https://github.com/apache/jena/pull/2798

   GitHub issue resolved #2797
   
   Pull request Description:
   
   This is a conservative solution to #2797 – it does not change any behavior from the outside perspective, and only changes the initialization of these two hashmaps to be lazy.
   
   This should improve RDF parsing performance.
   
   I'm marking "tests are included" because I don't see anything to test here that is not already covered by existing tests.
   
   ----
   
    - [x] Tests are included.
    - [x] Documentation change and updates are provided for the [Apache Jena website](https://github.com/apache/jena-site/)
    - [x] Commits have been squashed to remove intermediate development commit messages.
    - [x] Key commit messages start with the issue number (GH-xxxx)
   
   By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the [Contributor's Agreement](https://www.apache.org/licenses/contributor-agreements.html).
   
   ----
   
   See the [Apache Jena "Contributing" guide](https://github.com/apache/jena/blob/main/CONTRIBUTING.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


Re: [PR] GH-2797: Lazy init for ValidationState hash maps [jena]

Posted by "arne-bdt (via GitHub)" <gi...@apache.org>.
arne-bdt commented on code in PR #2798:
URL: https://github.com/apache/jena/pull/2798#discussion_r1817929455


##########
jena-core/src/main/java/org/apache/jena/ext/xerces/impl/validation/ValidationState.java:
##########
@@ -86,11 +85,25 @@ public void setSymbolTable(SymbolTable sTable) {
         fSymbolTable = sTable;
     }
 
+    /**
+     * Ensures that fIdTable and fIdRefTable are initialized.
+     */
+    private void ensureIdTablesAreInitialized() {
+        if (fIdTable == null) {
+            // REVISIT: Should replace with a lighter structure.
+            fIdTable = new HashMap();
+        }
+        if (fIdRefTable == null) {
+            fIdRefTable = new HashMap();
+        }
+    }
+
     /**
      * return null if all IDREF values have a corresponding ID value;
      * otherwise return the first IDREF value without a matching ID value.
      */
     public String checkIDRefID () {
+        ensureIdTablesAreInitialized();

Review Comment:
   Why init here? Instead:
   `if(fIdRefTable == null) return null;`
   
   and later in the while loop:
   
    if (fIdTable == null || !fIdTable.containsKey(key)) {



##########
jena-core/src/main/java/org/apache/jena/ext/xerces/impl/validation/ValidationState.java:
##########
@@ -169,16 +182,21 @@ public boolean isEntityUnparsed (String name) {
     // id
     @Override
     public boolean isIdDeclared(String name) {
+        if (fIdTable == null) {
+            return false;
+        }
         return fIdTable.containsKey(name);
     }
     @Override
     public void addId(String name) {
+        ensureIdTablesAreInitialized();

Review Comment:
   Only init fIdTable on demand here. 
   idRefTable is used in oder methods, so it might be that only one of the maps is needed.
   ```java
   if(fIdTable == null) {
       fIdTable = new HashMap();
   }
   ```



##########
jena-core/src/main/java/org/apache/jena/ext/xerces/impl/validation/ValidationState.java:
##########
@@ -169,16 +182,21 @@ public boolean isEntityUnparsed (String name) {
     // id
     @Override
     public boolean isIdDeclared(String name) {
+        if (fIdTable == null) {
+            return false;
+        }
         return fIdTable.containsKey(name);
     }
     @Override
     public void addId(String name) {
+        ensureIdTablesAreInitialized();
         fIdTable.put(name, fNullValue);
     }
 
     // idref
     @Override
     public void addIdRef(String name) {
+        ensureIdTablesAreInitialized();

Review Comment:
   Only init idRefTableon demand here. 
   fIdTable  is used in oder methods, so it might be that only one of the maps is needed.
   ```java
   if(idRefTable== null) {
       idRefTable= new HashMap();
   }
   ```



##########
jena-core/src/main/java/org/apache/jena/ext/xerces/impl/validation/ValidationState.java:
##########
@@ -86,11 +85,25 @@ public void setSymbolTable(SymbolTable sTable) {
         fSymbolTable = sTable;
     }
 
+    /**

Review Comment:
   This methos could be removed. The maps shoudl be individually created on demand, as they are used in differenct methods and not always togehter.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


Re: [PR] GH-2797: Lazy init for ValidationState hash maps [jena]

Posted by "arne-bdt (via GitHub)" <gi...@apache.org>.
arne-bdt commented on PR #2798:
URL: https://github.com/apache/jena/pull/2798#issuecomment-2439738743

   > ...I mean, I can make this thread-safe, but the real question is "what for" 😆
   
   Maybe add a comment to the javadoc header of the class with:
   `* This class is not thread safe.`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


Re: [PR] GH-2797: Lazy init for ValidationState hash maps [jena]

Posted by "Ostrzyciel (via GitHub)" <gi...@apache.org>.
Ostrzyciel commented on PR #2798:
URL: https://github.com/apache/jena/pull/2798#issuecomment-2439721022

   > Doesn't this allow for possible multithreading issues though? While with the `final` map that's mitigated... maybe looking at other data structures/map implementations could solve it in a different way (there's a comment about ligher impl...)
   
   The class is not thread-safe anyway, because `HashMap` is not thread-safe, so... it should be OK?
   
   We would have to worry about it if we had a shared instance of `ValidationState` across multiple parsers, but we don't. Long-term, I think this would be a good idea, but for that to happen I think most of this random xerces bloat would have to be removed first, as it's mostly dead code anyway.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


Re: [PR] GH-2797: Lazy init for ValidationState hash maps [jena]

Posted by "Ostrzyciel (via GitHub)" <gi...@apache.org>.
Ostrzyciel commented on PR #2798:
URL: https://github.com/apache/jena/pull/2798#issuecomment-2439761325

   > > ...I mean, I can make this thread-safe, but the real question is "what for" 😆
   > 
   > Maybe add a comment to the javadoc header of the class with: `* This class is not thread safe.`
   
   Done.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


Re: [PR] GH-2797: Lazy init for ValidationState hash maps [jena]

Posted by "arne-bdt (via GitHub)" <gi...@apache.org>.
arne-bdt merged PR #2798:
URL: https://github.com/apache/jena/pull/2798


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


Re: [PR] GH-2797: Lazy init for ValidationState hash maps [jena]

Posted by "Ostrzyciel (via GitHub)" <gi...@apache.org>.
Ostrzyciel commented on PR #2798:
URL: https://github.com/apache/jena/pull/2798#issuecomment-2439721448

   ...I mean, I can make this thread-safe, but the real question is "what for" :laughing: 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org