commit | f440fa0a38f69ca378f8e428cff016fa7028e1a9 | [log] [tgz] |
---|---|---|
author | Ben Gertzfield <bgertzfield@gmail.com> | Thu Jan 03 16:38:28 2013 -0800 |
committer | Ben Gertzfield <bgertzfield@gmail.com> | Thu Jan 03 16:57:00 2013 -0800 |
tree | 4b83a563abceb8bb9bf1bcac8b2ed60820507e62 | |
parent | b3dfdea27efc5c309deda8e4404c4b9aa9a9c4ee [diff] |
VersionUtil: Improve Android memory usage The Android runtime implements Class.getResourceAsStream() with a very memory-intensive cache, which holds the entire contents of the class's .jar in memory. A large Android app that uses Jackson will consume double the memory today. Since memory is very tight on most Android devices, this diff adds an alternative method to get version info for a package. In specific, we now generate a class com.fasterxml.jackson.core.json.PackageVersion at compile time. At run time, VersionUtil now checks the class's package to see if there's a class named 'PackageVersion', and if so, reads its 'VERSION' static field for the Version data for the package. (If not, we still use the existing VERSION.txt resource code as a fallback.) I have separate patches for jackson-databind and jackson-datatype-guava; it's easy to apply to other packages as well. This is a nice performance improvement as well; we no longer incur all the overhead of causing the runtime to open and cache the .jar (unzipping it, etc.) just to read the VERSION.txt resource. If the PackageVersion class doesn't exist, we'll of course fall back to the existing test to get version info. I confirmed using the Eclipse Memory Analyzer[1] that memory usage for a large app I work on was reduced by about 5 MB with this fix (as well as the jackson-databind and jackson-datatype-guava fixes). Unit tests included. [1] http://www.eclipse.org/mat/
This project contains core core low-level incremental ("streaming") parser and generator abstractions used by Jackson Data Processor. It also includes the default implementation of handler types (parser, generator) that handle JSON format. The core abstractions are not JSON specific, although naming does contain 'JSON' in many places, due to historical reasons. Only packages that specifically contain word 'json' are JSON-specific.
This package is the base on which Jackson data-binding package builds on.
Alternate data format implementations (like Smile (binary JSON), XML and CSV) also build on this base package, implementing the core interfaces, making it possible to use standard data-binding package regardless of underlying data format.
Project contains versions 2.0 and above: source code for earlier (1.x) versions is available from Codehaus SVN repository.
Project contains versions 2.0 and above: source code for earlier (1.x) versions is available from Codehaus SVN repository
Note that the main differences compared to 1.0 core jar are:
com.fasterxml.jackson.core
(instead of org.codehaus.jackson
)Functionality of this package is contained in Java package com.fasterxml.jackson.core
.
To use the package, you need to use following Maven dependency:
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.1.1</version> </dependency>
or download jars from Maven repository or Download page. Core jar is a functional OSGi bundle, with proper import/export declarations.
Package has no external dependencies, except for testing (which uses JUnit
).
For non-Maven use cases, you download jars from Central Maven repository or Download page.
Core jar is also a functional OSGi bundle, with proper import/export declarations, so it can be use on OSGi container as is.
Usage typically starts with creation of a reusable (and thread-safe, once configured) JsonFactory
instance:
JsonFactory factory = new JsonFactory(); // configure, if necessary: factory.enable(JsonParser.Feature.ALLOW_COMMENTS);
Alternatively, you have a ObjectMapper
(from Jackson Databind package) handy; if so, you can do:
JsonFactory factory = objectMapper.getJsonFactory();
All reading is by using JsonParser
(or its sub-classes, in case of data formats other than JSON), instance of which is constructed by JsonFactory
:
(TO BE WRITTEN)
All writing is by using JsonGenerator
(or its sub-classes, in case of data formats other than JSON), instance of which is constructed by JsonFactory
:
(TO BE WRITTEN)
Project-specific documentation:
Related: