Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

escaper caching #9

Open
rob42 opened this issue Jan 28, 2015 · 2 comments
Open

escaper caching #9

rob42 opened this issue Jan 28, 2015 · 2 comments

Comments

@rob42
Copy link

rob42 commented Jan 28, 2015

Hi,
Found I can get a huge increase in speed by caching in the escaper. In my case I am outputting periodic updates to the same data, so its especially useful. the escape method was using 5% CPU, now its below 1%. I know you dont want any dependencies but I used Google guava cache. Code is here if you want to use it:

escapeHash = CacheBuilder.newBuilder()
                   .maximumSize(1000)
                   .build(
                           new CacheLoader<CharSequence, String>() {
                             public String load(CharSequence plainText) throws Exception {
                                 StringBuilder escapedString = new StringBuilder(plainText.length() + 20);
                                try {
                                  escapeJsonString(plainText, escapedString);
                                } catch (IOException e) {
                                  throw new RuntimeException(e);
                                }
                                return escapedString.toString();
                             }
                           });
      }

      public String escapeJsonString(CharSequence plainText) {
        return escapeHash.getUnchecked(plainText);
      }
@bolerio
Copy link
Owner

bolerio commented Jan 28, 2015

That's interesting and I'd do something about it. You are right, I wouldn't want any dependencies on the project :)

@rob42
Copy link
Author

rob42 commented Jan 29, 2015

BTW I treid a raw ConcurrentHashMap, but it kept growing and slowing, so that doesnt work without an evictor.

@bolerio bolerio added this to the 1.5 milestone Jul 4, 2016
@bolerio bolerio removed this from the 1.5 milestone Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants