Github user trkurc commented on the pull request:

    https://github.com/apache/nifi/pull/202#issuecomment-178942251
  
    I did a quick experiment (code below), generated a 10^20 "UUID"'s using a 
few mechanisms
    
    1. as you did in this pr (~120ms)
    2. an slightly different version of what is in the PR  (~55ms)
    3. using UUID with the atomic long as the low order bits (~800ms)
    4. what was there originally (~3400ms)
    5. Using JUG [1] to generate a time-based UUID (~800ms)
    
    So, I think it is a net win with changing the method you created to return 
a String rather than a Long (based on 1 vs 2). On the long as a string vs UUID 
as a string, although it is faster by a factor of  6, I do think returning a 
UUID as a string may better fit the contract of the UUID core attribute. 
Although pretty much everywhere it is stored, it is done so as a String, the 
comments clearly say UUID [2]. I'm not sure the technical debt accrued for a 
Long vs UUID performance increase is a good trade in this instance. 
    
    Side note - the JUG github page is an interesting read. There are some good 
benchmarks talking about how awesome it is.
    
    [1] https://github.com/cowtowncoder/java-uuid-generator
    [2] 
https://github.com/apache/nifi/blob/master/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/flowfile/attributes/CoreAttributes.java#L34
    ```java
        public static void main(String args[]){
            long iter = 1<<20;
            AtomicLong ai = new AtomicLong(0);
            long now = System.currentTimeMillis();
            for(int i=0; i < iter; i++) {
                Long x = ai.getAndIncrement();
                String x2 = x.toString();
            }
            System.out.printf("%d elapsed\n", (System.currentTimeMillis() - now 
));
    
            now = System.currentTimeMillis();
            for(int i=0; i < iter; i++) {
                
                String x2 = Long.toString(ai.getAndIncrement());
            }
            System.out.printf("%d elapsed\n", (System.currentTimeMillis() - now 
));
    
            now = System.currentTimeMillis();
            for(int i=0; i < iter; i++) {
                UUID u = new UUID(0, ai.getAndIncrement());
                String x2 = u.toString();
            }
            System.out.printf("%d elapsed\n", (System.currentTimeMillis() - now 
));
            
            now = System.currentTimeMillis();
            for(int i=0; i < iter; i++) {
                UUID u = UUID.randomUUID();
                String x2 = u.toString();
            }
            System.out.printf("%d elapsed\n", (System.currentTimeMillis() - now 
));
        
            now = System.currentTimeMillis();
            TimeBasedGenerator g = Generators.timeBasedGenerator();
            for(int i=0; i < iter; i++) {
                UUID u = g.generate();
                String x2 = u.toString();
            }
            System.out.printf("%d elapsed\n", (System.currentTimeMillis() - now 
));
        }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to